特定查询字符串的重写规则
RewriteRule for specific Query String
我想用 .htaccess 重写一个 URL 这样的
https://example.com/pages/games/demons-souls/?page=mods
看起来像这样
https://example.com/games/demons-souls/mods
我使用以下代码成功隐藏了 URL 中的页面文件夹:
Options +MultiViews
RewriteEngine On
# Rewrite "/games/<anything>" to "/pages/games/<anything>"
RewriteCond %{REQUEST_URI} !^/pages/games
RewriteRule ^games($|/.*) pages/[=10=]
但是我需要一个适合查询字符串的 RewriteRule。我试过了但是没用...
RewriteRule ^([^/]*)/([^/]*)$ /index.php?page= [L,QSA]
非常感谢您的帮助。
你可以这样:
Options +MultiViews
RewriteEngine On
# Rewrite "/games/<foo>/<bar>" to "/pages/games/<foo>/?page=<bar>"
RewriteRule ^(games/[\w-]+)/([\w-]+)/?$ pages//?page= [L,NC,QSA]
# Rewrite "/games/<anything>" to "/pages/games/<anything>"
RewriteRule ^games($|/.*) pages/[=10=] [L,NC]
我想用 .htaccess 重写一个 URL 这样的
https://example.com/pages/games/demons-souls/?page=mods
看起来像这样
https://example.com/games/demons-souls/mods
我使用以下代码成功隐藏了 URL 中的页面文件夹:
Options +MultiViews
RewriteEngine On
# Rewrite "/games/<anything>" to "/pages/games/<anything>"
RewriteCond %{REQUEST_URI} !^/pages/games
RewriteRule ^games($|/.*) pages/[=10=]
但是我需要一个适合查询字符串的 RewriteRule。我试过了但是没用...
RewriteRule ^([^/]*)/([^/]*)$ /index.php?page= [L,QSA]
非常感谢您的帮助。
你可以这样:
Options +MultiViews
RewriteEngine On
# Rewrite "/games/<foo>/<bar>" to "/pages/games/<foo>/?page=<bar>"
RewriteRule ^(games/[\w-]+)/([\w-]+)/?$ pages//?page= [L,NC,QSA]
# Rewrite "/games/<anything>" to "/pages/games/<anything>"
RewriteRule ^games($|/.*) pages/[=10=] [L,NC]