Removing index.php and another page inside the root folder from URL with .htaccess

放肆的年华 提交于 2019-12-13 02:20:43

问题


In my Root folder I have index.php and profile.php.

Currently I'm using these rules for rewrite my index.php

from example.com/index.php?a=profile&u=user1 to example.com/profile&u=user1

RewriteEngine On
RewriteCond %{request_filename} -f
RewriteRule ^(.*) $1 [L]
RewriteRule ^(([^/]*)+)(/([^/]{0,32})(/.+)?)?$  index.php?a=$1&q=$3     [L]
RewriteRule ^welcome/([^/]+)/?$         index.php?a=welcome             [NC]
RewriteRule ^page/([^/]+)/?$            index.php?a=page&filter=$1      [NC]

It works fine but now I want to rewrite my URL for profile.php page too, like this:

from example.com/profile.php?u=user1 to example.com/user1

How can I edit my .htaccess to rewrite profile.php together?


回答1:


Based on question and comments above here are the rules that should work for you:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^profile/([^/]+)/?$ profile.php?u=$1 [NC,QSA,L]

RewriteRule ^welcome/([^/]+)/?$ index.php?a=welcome&filter=$1 [NC,QSA,L]

RewriteRule ^page/([^/]+)/?$ index.php?a=page&filter=$1 [NC,QSA,L]

RewriteRule ^(([^/]+)+)(/([^/]{0,32})(/.+)?)?$ index.php?a=$1&q=$3 [L,QSA]


来源:https://stackoverflow.com/questions/36953282/removing-index-php-and-another-page-inside-the-root-folder-from-url-with-htacce

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