【问题标题】:how to add index.php in the URL through htaccess如何通过htaccess在URL中添加index.php
【发布时间】:2015-07-06 06:50:28
【问题描述】:

实际上我需要通过htaccess文件在我的应用程序URL中添加index.php。

我的网址是这样的。

http://localhost:8080/myapp/xyz/abs.html

我需要把这个改成。

http://localhost:8080/myapp/index.php/xyz/abs.html

谁能告诉我我需要在 htaccess 文件中写什么。

任何帮助将不胜感激。

谢谢。

【问题讨论】:

  • 你在使用任何框架吗?,你现在的.htaccess是什么?

标签: php .htaccess mod-rewrite url-rewriting


【解决方案1】:

/myapp/.htaccess中有这条规则:

RewriteEngine On
RewriteBase /myapp/

# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.+) index.php/$1 [L]

【讨论】:

    【解决方案2】:

    大概需要内部重写,而不是外部重定向?在这种情况下,请尝试以下操作,在根 .htaccess 文件中使用 mod_rewrite:

    RewriteEngine On
    RewriteCond %{REQUEST_URI} !/index\.php/
    RewriteRule ^myapp/(.*) /myapp/index.php/$1 [L]
    

    RewriteCond 指令是防止重写循环所必需的。 (只有在它还没有包含“/index.php/”时才重写。)

    【讨论】:

      【解决方案3】:

      在你的 htaccess 中试试这个

      RewriteEngine on 
      RewriteCond %{THE_REQUEST} /myapp/xyz/([^.]+)\.html [NC]
      RewriteRule ^ /myapp/index.php/xyz/%1.html [R,L,NC]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-17
        • 2014-08-24
        • 1970-01-01
        相关资源
        最近更新 更多