2012-02-21 131 views
1

我有一個住在以下領域的一個項目:的.htaccess重寫多個域

http://www.example.com/PROJECT/ 

項目中,有三個子頁面,其中有網頁的結構是這樣的:

http://www.example.com/PROJECT/first-subpage.php?Page_ID=12345 
http://www.example.com/PROJECT/second-subpage.php?Page_ID=12345 
http://www.example.com/PROJECT/third-subpage.php?Page_ID=12345 

我試圖爲其中的每一個寫多個Mod重寫規則,以便我可以擁有以下樣式重定向的url,例如:

http://www.example.com/PROJECT/first-section/12345/some-other-text-here 
>> 
http://www.example.com/PROJECT/first-subpage.php?Page_ID=12345 

這裏是我的,但我一直沒能獲得比賽得到回升,根據本.htaccess tester

這裏是我目前的.htaccess文件:

RewriteEngine On 
RewriteBase /PROJECT/ 

<filesMatch "^(/first-section/.*)"> 
     Options +FollowSymlinks 
     RewriteRule ^/(.*)$/(.*)$/(.*)$ /first-subpage.php?page_ID=$2 
</filesMatch> 

<filesMatch "^(/second-section/.*)"> 
     Options +FollowSymlinks 
     RewriteRule ^/(.*)$/(.*)$/(.*)$ /second-subpage.php?page_ID=$2 
</filesMatch> 

<filesMatch "^(/third-section/.*)"> 
     Options +FollowSymlinks 
     RewriteRule ^/(.*)$/(.*)$/(.*)$ /third-subpage.php?page_ID=$2 
</filesMatch> 

我怎樣才能得到這些規則來正確匹配url?

回答

2
Options +FollowSymlinks 
RewriteEngine on 
RewriteRule ^PROJECT/first-section/([^/]+)/([^/]+) /PROJECT/first-subpage.php?Page_ID=$1 [NC] 
RewriteRule ^PROJECT/second-section/([^/]+)/([^/]+) /PROJECT/second-subpage.php?Page_ID=$1 [NC] 
RewriteRule ^PROJECT/third-section/([^/]+)/([^/]+) /PROJECT/third-subpage.php?Page_ID=$1 [NC] 

注:請仔細檢查了var名字,因爲它是大小寫敏感的,你在這個問題變量是Page_ID,這是在你的.htaccess代碼page_ID

+0

如果你的htaccess位於/ PROJECT /文件夾中,然後刪除'PROJECT /'(只有'^'後面的那個) – Gerben 2012-02-21 17:21:31

+0

@Gerben正確! – Ashraf 2012-02-21 17:53:14