繁体   English   中英

使用mod_rewrite更改url结构

[英]changing url structure with mod_rewrite

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

一切完成之后,现在* client想要更改URL结构,如下所示

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

尝试这样的事情:

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

通过httpd.conf启用mod_rewrite和.htaccess,然后将此代码放在DOCUMENT_ROOT目录下的.htaccess

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]

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM