【问题标题】:Redirect Get-Parameter with .htaccess使用 .htaccess 重定向 Get-Parameter
【发布时间】:2014-06-20 12:09:13
【问题描述】:

我将在 .htaccess 的帮助下重定向此网址:

http://www.example.com/index.php?q=where is new york?&start=0&type=web

到:

http://www.example.com/search/where is new york?/0/web

知道我如何实施这个计划吗? 重要的是,问号不会重置其他 GET-Value。 谢谢!

【问题讨论】:

    标签: php regex apache .htaccess mod-rewrite


    【解决方案1】:

    在你的根 .htaccess 中这样设置:

    RewriteEngine On
    
    RewriteCond %{THE_REQUEST} \s/+index\.php\?q=([^\s&]+)&start=([^\s&]+)&type=([^\s&]+) [NC]
    RewriteRule ^ /search/%1/%2/%3? [R=302,L]
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(search/[^/]+)/?$ /$1\%3F/%{QUERY_STRING}? [L,NC,NE]
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^search/([^/]+)/([^/]+)/([^/]+)/?$ search.php?q=$1&start=$2&type=$3 [L,QSA,NC]
    

    【讨论】:

    • 不客气,很高兴它成功了。实际上这是一个棘手的重写。
    【解决方案2】:
    RewriteCond %{QUERY_STRING} q=(.*)&start=(.*)&type=(.*)
    RewriteRule /index\.php search/%1?/%2/%3
    

    对于查询字符串,您需要使用条件。进一步的帮助可以找到here

    【讨论】:

      【解决方案3】:

      如果要重写url:

      RewriteEngine On
      RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /index.php?q=$1&start=$2&type=$3 [L]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-03-18
        • 1970-01-01
        • 2021-05-01
        • 1970-01-01
        • 2013-09-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多