当我在 print-salon.loc/land/badges/city-moscow
时,我想重定向到 print-salon.loc/land/badges/?city=moscow
> 我尝试使用这段代码:
# BEGIN WPSuperCache
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
AddDefaultCharset UTF-8
RewriteCond %{REQUEST_URI} ^land/badges/city-([a-zA-Z]+)$
RewriteRule ^(.*) /land/badges/index.php?city=$1 [L]
</IfModule>
# END WPSuperCache
但是重定向没有发生。
最佳答案
尝试这个,希望这个会有所帮助。您可以测试下面添加的行 here
问题:
1. You skipped
/
inREQUEST_URI
matching2. You should use
%1
instead of$1
3. You should use
R
flag for redirection.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
AddDefaultCharset UTF-8
RewriteCond %{REQUEST_URI} ^/land/badges/city-([a-zA-Z]+)$
RewriteRule ^(.*) /land/badges/index.php?city=%1 [L,R]
</IfModule>
关于php - 在 htaccess 中重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45876204/