php - 在 htaccess 中重定向

标签 php regex .htaccess redirect

当我在 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 / in REQUEST_URI matching

2. 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/

相关文章:

php - 在 MySQL 中,如何将包含 "similar"数据的行返回到我所请求的内容?

javascript - 真正的 Ajax uploader 不会显示在 DIV 中

.htaccess - 不要重写静态 css/js/img 文件

php - 如何从url中隐藏GET变量

PHP 删除功能损坏

php - 能够使用 Laravel 在运行时更改数据库连接

python - 正则表达式获取测量值

regex - 使用 Linux Shell 正则表达式匹配文件名

regex - 如何至少匹配包含每个元音的单词一次?

php - 如何将错误的查询字符串重定向到自定义错误页面+ 404 状态