Remove 'index.php' from url without removing parameters in .htaccess

こ雲淡風輕ζ 提交于 2019-12-13 18:56:13

问题


I have a condition for url redirect like,

www.domain.com/something/anotherthing/index.php

i need the above url to redirect to

www.domain.com/something/anotherthing/

If i go to

www.domain.com/index.php/something/anotherthing

i want to redirect to

www.domain.com/something/anotherthing

i have a redirect htaccess rule for this

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

RewriteRule ^ /%1$1 [R=301,L]

But this works for the first condition but in the later it redirect me to the root page. Can anyone please help in this redirection.

Thanks in Advance.


回答1:


Try something like this:

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

That should handle any location of /index.php.



来源:https://stackoverflow.com/questions/14393253/remove-index-php-from-url-without-removing-parameters-in-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!