How do you remove index.php from a url using mod_write, while still allowing php to see the path with index.php in it?

后端 未结 2 1523
轻奢々
轻奢々 2021-01-27 04:56

For the past 3 days I have been playing around with Apache\'s mod_rewrite trying to get it to remove index.php from my url, while php still needs to see it in the path.

2条回答
  •  渐次进展
    2021-01-27 05:20

    This rule:

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
    RewriteRule ^ /%1 [R=301,L]
    

    Needs to look like this:

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\ /index\.php(.*)\  [NC]
    RewriteRule ^ /%1 [R=301,L]
    

    Also note that RewriteRule ^(.*)$ index.php?$1 [L,QSA] doesn't create a URI that looks like this /index.php/Page/Param1/Param2, it creates a query string that looks like this: /index.php?Page/Param1/Param2. Which isn't at all what you said PHP needs to see.

提交回复
热议问题