使用mod_rewrite更改url结构

时间:2012-05-29 14:28:32

标签: php .htaccess url mod-rewrite

对于我们正在开发的新网站,网址结构如下。

一切都完成后,现在*客户端想要更改URL结构,如下所示

我如何根据mod_rewrite / htaccess的要求更改此内容?我不是htaccess的专家,我们现在无法更改平台。

3 个答案:

答案 0 :(得分:0)

尝试这样的事情:

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

答案 1 :(得分:0)

通过httpd.conf启用mod_rewrite和.htaccess,然后将此代码放在.htaccess目录下的DOCUMENT_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]

答案 2 :(得分:0)

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