【问题标题】:redirect with .htaccess old url to the new url使用 .htaccess 旧网址重定向到新网址
【发布时间】:2013-11-03 22:01:16
【问题描述】:

伙计们,谁能帮我用一个 .htaccess 规则来重定向这种 url 类型:

旧网址:video/displayresults/?pattern=searchedword

新网址:video/search/?searchword=searchedword

所以我想将任何旧网址重定向到新网址

谢谢

【问题讨论】:

    标签: .htaccess redirect rule


    【解决方案1】:

    您想查找 htaccess RewriteRule 指令。您需要构建它捕获的正则表达式“/displayresults/?”并将其解析为“/search/”。确保您启用了 mod_rewrite

    例子:

    重写规则 ^(.)/displayresults/(.)$ $1/search/$2

    这假定 displayresults 是一个文件夹名称。

    【讨论】:

    • Ive found for now this:<br/> RewriteCond %{QUERY_STRING} pattern=(.*) RewriteRule ^(.*) /video/search/?searchword=%1 [L,R=301]` 但我想要使其仅适用于具有 /video/displayresullts/ 的网址
    【解决方案2】:

    启用mod_rewrite.htaccesshttpd.conf(如果尚未启用),然后将此代码放入您的DOCUMENT_ROOT/.htaccess 文件中:

    RewriteEngine On
    
    RewriteCond %{QUERY_STRING} ^pattern=(.*)$ [NC]
    RewriteRule ^(video)/displayresults/?$ /$1/search/?searchword=%1 [L,NC,R=301]
    

    【讨论】:

      猜你喜欢
      • 2021-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-22
      • 2013-10-16
      • 2021-10-21
      相关资源
      最近更新 更多