2012-02-21 132 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