【问题标题】:how to redirect with htaccess without changing the URL in browser如何在不更改浏览器中的 URL 的情况下使用 htaccess 进行重定向
【发布时间】:2013-07-26 09:11:11
【问题描述】:

我有一个普通的动态网址,我希望它使 SEO 友好,如下所示

我的网址是

domain.com/search.php?v1=mobiles&v2=nokia

domain.com/search/mobiles/nokia

请帮忙

【问题讨论】:

    标签: php apache .htaccess xampp


    【解决方案1】:

    您需要使用 .htaccess 文件来执行此重写操作,而无需在浏览器中更改 url, 试试下面的代码

    RewriteEngine On  #remove this if already added
    RewriteRule ^search/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$    search.php?s1=$1&s2=$2    [NC,L] 
    

    【讨论】:

      【解决方案2】:

      我会这样做:

      RewriteEngine On  #if not already on. 
      RewriteCond %{REQUEST_FILENAME} !-f #only if it is not calling a file that actually exists
      RewriteCond %{REQUEST_FILENAME} !-d #only if it is not calling a directory that actually exists.
      RewriteRule ([a-z0-9]+)(/*)([a-z0-9]*)(/*)([a-z0-9]*)(/*) search.php?v1=$1&v2=$3 [L,NC,QSA]
      

      即使你只去 /mobile/ 这也能工作(假设你的 search.php 可以处理。)

      HTH

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-12-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-01-14
        • 1970-01-01
        • 2017-02-16
        相关资源
        最近更新 更多