2011-09-19 44 views
3

我有2個.htaccess文件需要合併在一起。一個是由wordpress生成的,另一個是該網站的現有.htaccess文件。 2.文件如下:由WordPress產生組合2 .htaccess文件

RewriteEngine on 
RewriteCond %{HTTP_HOST} !^www\.mywebsite\.com$ 
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [R=301] 

RewriteRule ^postreview/$ /viewreview.php [NC,PT,L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

RewriteRule ^.*$ ./template2.php 


<IfModule mod_security.c> 
    # Turn off mod_security filtering. 
    SecFilterEngine Off 

    # The below probably isn't needed, 
    # but better safe than sorry. 
    SecFilterScanPOST Off 
</IfModule> 

php_flag session.use_trans_sid off 

第二個文件:

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase /projectcars/ 
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /projectcars/index.php [L] 
</IfModule> 

我試過幾種方法把它們結合在一起,但我要麼得到一個重定向錯誤或內部服務器錯誤。

回答

6

這裏是我的解決辦法:

RewriteEngine on 
RewriteCond %{HTTP_HOST} !^www.domain.com [NC] 
RewriteRule (.*) http://www.domain.com/$1 [R=301,L] 

RewriteBase/

RewriteRule ^postreview(\/?)$ /viewreview.php [QSA,NC,PT,L] 

RewriteRule ^projectcars/index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^projectcars/(.*)$ /projectcars/index.php [L] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule (.*) template2.php [NC,L] 

<IfModule mod_security.c> 
SecFilterEngine Off 
SecFilterScanPOST Off 
</IfModule> 

php_flag session.use_trans_sid off