【问题标题】:Redirect in htaccess在 htaccess 中重定向
【发布时间】:2018-02-03 04:44:08
【问题描述】:
当我在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
但不会发生重定向。
【问题讨论】:
标签:
php
regex
.htaccess
redirect
【解决方案1】:
试试这个,希望这个会有所帮助。您可以测试以下添加的行here
问题:
1.你在REQUEST_URI匹配中跳过了/
2.你应该使用%1而不是$1
3.您应该使用R 标志进行重定向。
<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>
【解决方案2】:
也许我描述的问题不正确,但这里是解决方案
RewriteRule ^land/([-a-zA-Z0-9]+)/city-(.*)$ http://%{HTTP_HOST}/land/$1/index.php?city=$2 [L]