【问题标题】:How to write seo friendly url's using htaccess?如何使用 htaccess 编写 seo 友好的 url?
【发布时间】:2012-08-14 16:23:40
【问题描述】:

我想为我的网站创建 seo 友好的 url。我想从 .htaccess 文件创建它。我对 .htaccess 知之甚少

我有以下网址 http://www.testsite.com/index.php?dispatch=flowers_search.flowers_search_result&city=Pune&type=Carnation

我需要如下显示url, http://www.testsite.com/flowers/Pune/Carnation

谢谢

【问题讨论】:

    标签: .htaccess seo clean-urls


    【解决方案1】:

    http://www.generateit.net/mod-rewrite/

    导致:

    RewriteEngine On
    RewriteRule ^([^/]*)/([^/]*)$ /index.php?dispatch=flowers_search.flowers_search_result&city=$1&type=$2 [L]
    

    【讨论】:

      【解决方案2】:
      <IfModule mod_rewrite.c>
          RewriteEngine On
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteRule . /index.php?args=%{REQUEST_URI} [L]
      </IfModule>
      

      这会将您的查询字符串放入一个变量中,您可以在页面上将其用作$_GET['args']。所以你打电话:

      http://www.testsite.com/flowers/Pune/Carnation

      但您实际上是在显示页面:

      http://www.testsite.com/?args=flowers/Pune/Carnation

      然后您可以使用 $_GET['args'] 并按照您的意愿解析它:

      $args = explode('/', $_GET['args']);
      array_shift($args); // this take an empty value off of the first item in the array
      $dispatch = $args[0];
      $city = $args[1];
      $type = $args[2];
      

      等等。

      【讨论】:

        【解决方案3】:

        只需尝试以下方法:

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

        我认为这可以帮助您解决问题。

        【讨论】:

          猜你喜欢
          • 2023-03-24
          • 2018-09-10
          • 1970-01-01
          • 2015-03-25
          • 2021-07-06
          • 2015-01-04
          • 2021-07-23
          • 1970-01-01
          相关资源
          最近更新 更多