【问题标题】:how to redirect multi parameter url using htaccess如何使用 htaccess 重定向多参数 url
【发布时间】:2016-06-11 11:03:10
【问题描述】:

我的旧网址是

http://www.tuitionok.com/result.php?sr=0&city=patna&text=computer+home+tuition+in+patna&type=home-tuition#t

新的网址是

http://www.tuitionok.com/patna/home-tuition/computer-home-tuition-in-patna/0

我正在尝试将旧网址转发到新网址

我正在使用这个 .htaccess 代码

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)$ result.php?city=$1&type=$2&text=$3&sr=$4 [L]

我已成功获取参数值并显示结果。但实际问题是旧网址和新网址都可以正常工作。我认为应该修改我的 htaccess 文件以将 url 强制重定向到新的 url。

【问题讨论】:

    标签: php apache .htaccess redirect mod-rewrite


    【解决方案1】:

    试试这个:

    Options +FollowSymLinks -Multiviews
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)$ result.php?city=$1&type=$2&text=$3&sr=$4 [L]
    RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/$ result.php?city=$1&type=$2&text=$3&sr=$4 [L]
    

    【讨论】:

    • 它没有重定向到新的 url
    • 您必须通过连字符来更改具有空格的变量值,例如 $type = str_replace(' ','-', $type);
    • 变量中没有空格我也使用了这个 url tuitionok.com/… 但没有重定向
    • 你能显示 php 代码以便我了解你实际在做什么吗?
    • 这里是 php $query="select * from organization where type='$type' and display=1 and $city like '%$city%' and keyword like '%$'中的查询代码text%' 限制 $sr, 10";
    猜你喜欢
    • 1970-01-01
    • 2017-02-04
    • 1970-01-01
    • 1970-01-01
    • 2014-08-10
    • 2021-03-21
    • 2016-01-09
    • 2017-01-06
    • 1970-01-01
    相关资源
    最近更新 更多