2016-02-05 86 views
0

我有一些麻煩理解.htacess基本上我試圖有多個重寫規則;例如我有一個配置文件頁面,然後我也想重寫索引頁面,那麼這將如何完成;在我以前的嘗試中,我只能使用一個重寫規則,也許我做錯了什麼;我有一個鏈接/profile/profile.php?user=$username和索引頁面account.php?page=featured的個人資料頁面我怎樣才能讓個人資料頁面看起來像/account/$username和帳戶頁面看起來像/account/featured謝謝你,我怎麼會然後添加更多的後面呢?多個htacess重寫規則

account.php文件位於根目錄下。

RewriteEngine On 
RewriteBase/
RewriteRule ^tag/([^/]+)/([^/]+)$ /tag/index.php?hash=$1&cat=$2 
Options All -Indexes 
ErrorDocument 403 Denied 

是它使用#標籤,並顯示他們喜歡這個/tag/$hashtag當我試圖複製並粘貼這然後在它使用它沒有工作我目前的.htaccess。

+0

發表您的當前代碼 –

+0

@ImmortalDude做過了:3 – Johnny

+1

Apache將無法知道需要重寫哪個文件。也許用'/ profile/username'替換'/ account/username'並編寫規則來保持它們的分離。或者,更好的是,'/ account/username/profile'。 –

回答

2

正如我的評論中提到的,Apache無法分辨要重寫哪個文件。所以你需要改變一個URI結構。作爲建議,請更改配置文件的配置。

下面是一個例子向您展示如何做到這一點:

RewriteRule ^tag/([^/]+)/([^/]+)$ /tag/index.php?hash=$1&cat=$2 [L] 
RewriteRule ^account/([^/]+) /account.php?page=$1 [L] 
RewriteRule ^profile/([^/]+) /profile/profile.php?user=$1 [L] 

記住[L]標誌,這將導致複寫時找到匹配停止。

+1

完美的答案非常感謝你非常有用,偉大的迴應 – Johnny