簡體   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