【问题标题】:changing url structure with mod_rewrite用 mod_rewrite 改变 url 结构
【发布时间】:2012-05-29 14:28:31
【问题描述】:

对于我们正在开发的一个新站点,URL结构如下。

一切都完成后,现在*client想要改变URL结构如下

如何根据他的要求使用 mod_rewrite / htaccess 进行更改?我不是 htaccess 专家,我们现在无法更改平台。

【问题讨论】:

    标签: php .htaccess url mod-rewrite


    【解决方案1】:

    试试这样的:

    RewriteEngine on
    RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ $1?$2/$3 [L,QSA]
    RewriteRule (.*?)/?$ index.php?$1 [L,QSA]
    

    【讨论】:

      【解决方案2】:

      htaccess 示例

      <IfModule mod_rewrite.c>
          RewriteEngine On
      
          # About Us ---------------------------------------
          RewriteRule ^aboutus.html*$ index.php?page=aboutus [L]
      
      </IfModule>
      

      mod 重写 php 示例

      function replace_for_mod_rewrite($s) {
      $siteUrl = "Your site url";
      $urlin = array( "`".$siteUrl."/index\.php\?page=aboutus(['|\"|#])`is" );
      $urlout = array( $siteUrl."/aboutus.html\\1" );
      $s = preg_replace($urlin, $urlout, $s);
      }
      

      更多详情:TechNew.In

      【讨论】:

        【解决方案3】:

        通过httpd.conf启用mod_rewrite和.htaccess,然后把这段代码放到你.htaccessDOCUMENT_ROOT目录下:

        Options +FollowSymLinks -MultiViews
        # Turn mod_rewrite on
        RewriteEngine On
        RewriteBase /
        
        ## If the request is for a valid directory
        RewriteCond %{REQUEST_FILENAME} -d [OR]
        ## If the request is for a valid file
        RewriteCond %{REQUEST_FILENAME} -f [OR]
        ## If the request is for a valid link
        RewriteCond %{REQUEST_FILENAME} -l
        ## don't do anything
        RewriteRule ^ - [L]
        
        RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ index.php?$1=$2/$3 [L,QSA]
        
        RewriteRule (.*?)/?$ index.php?$1 [L,QSA]
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-08-24
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2010-10-12
          • 2016-08-28
          • 2012-07-20
          相关资源
          最近更新 更多