将规则重写为 URL 友好页面和用户配置文件

ReWrite Rule to a URL Friendly Page and User Profile

我想使用两个 RewriteRules 将页面和用户重定向到右侧 link 但我无法实现我想要的,也许有人可以帮助我...

我想重定向任何 Url 友好页面:

http://www.example.com/my-url-friendly-page

http://www.example.com/index.php?cod=my-url-friendly-page

AND 用户个人资料来自:

http://www.example.com/profile/username

http://www.example.com/profile/index.php?user=username

这是我的 htaccess,第一个规则工作正常,但我无法修复第二个...

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php?cod=
  RewriteRule ^/profile/(.*)$ index.php?user= [QSA,L]
</IfModule>

谁能帮我解决这个问题?

像这样重新排列您的规则:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  RewriteRule ^profile/(.*)$ index.php?user= [QSA,L,NC]

  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php?cod= [L,QSA]
</IfModule>