.htaccess 将规则重写为URL友好的页面和用户配置文件
我想使用两个重写规则将页面和用户重定向到正确的链接,但我不能实现我想要的,也许有人可以帮助我 我想从以下位置重定向任何Url友好页面:.htaccess 将规则重写为URL友好的页面和用户配置文件,.htaccess,mod-rewrite,url-rewriting,.htaccess,Mod Rewrite,Url Rewriting,我想使用两个重写规则将页面和用户重定向到正确的链接,但我不能实现我想要的,也许有人可以帮助我 我想从以下位置重定向任何Url友好页面: http://www.example.com/my-url-friendly-page 到 和用户配置文件来自: http://www.example.com/profile/username 到 这是我的htaccess,第一条规则正常工作,但我无法修复第二条规则 <IfModule mod_rewrite.c> RewriteEngine
http://www.example.com/my-url-friendly-page
到
和用户配置文件来自:
http://www.example.com/profile/username
到
这是我的htaccess,第一条规则正常工作,但我无法修复第二条规则
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?cod=$1
RewriteRule ^/profile/(.*)$ index.php?user=$1 [QSA,L]
</IfModule>
重新启动发动机
重写基/
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则^(.*)$index.php?cod=$1
重写规则^/profile/(.*)$index.php?user=$1[QSA,L]
有人能帮我吗?按如下方式重新排列规则:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^profile/(.*)$ index.php?user=$1 [QSA,L,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?cod=$1 [L,QSA]
</IfModule>
重新启动发动机
重写基/
重写规则^profile/(*)$index.php?用户=$1[QSA,L,NC]
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则^(.*)$index.php?cod=$1[L,QSA]
谢谢,成功了!你能解释为什么规则顺序改变了结果吗?如果配置文件规则排在第二位,那么其他规则优先,因为它匹配*
,因此匹配所有内容,并导致配置文件规则永远不会执行。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?cod=$1
RewriteRule ^/profile/(.*)$ index.php?user=$1 [QSA,L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^profile/(.*)$ index.php?user=$1 [QSA,L,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?cod=$1 [L,QSA]
</IfModule>