【发布时间】:2012-05-29 14:28:31
【问题描述】:
对于我们正在开发的一个新站点,URL结构如下。
一切都完成后,现在*client想要改变URL结构如下
如何根据他的要求使用 mod_rewrite / htaccess 进行更改?我不是 htaccess 专家,我们现在无法更改平台。
【问题讨论】:
标签: php .htaccess url mod-rewrite
对于我们正在开发的一个新站点,URL结构如下。
一切都完成后,现在*client想要改变URL结构如下
如何根据他的要求使用 mod_rewrite / htaccess 进行更改?我不是 htaccess 专家,我们现在无法更改平台。
【问题讨论】:
标签: php .htaccess url mod-rewrite
试试这样的:
RewriteEngine on
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ $1?$2/$3 [L,QSA]
RewriteRule (.*?)/?$ index.php?$1 [L,QSA]
【讨论】:
<IfModule mod_rewrite.c>
RewriteEngine On
# About Us ---------------------------------------
RewriteRule ^aboutus.html*$ index.php?page=aboutus [L]
</IfModule>
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
【讨论】:
通过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]
【讨论】: