2013-01-04 45 views
1

我有兩個不同的.htaccess文件,每個文件做不同的事情,當我把它們合併在一起時,它們不會一起工作。結合了兩個.htaccess重寫文件

第一個讓我進入www.mydoman.com/test,並將它意味着www.mydomain.com/index.php?page=test

RewriteRule ^([A-Za-z0-9-_]+)/?$ index.php?subclass=$1 [NC,L] 
RewriteRule ^.* index.php [NC,L] 

第二個文件切斷從延伸.html和.php文件等都可以使用www.mydomain.com/about insted的www.mydoman.com/about.php

Options +FollowSymLinks -MultiViews 
# Turn mod_rewrite on 
RewriteEngine On 

RewriteBase /cl_clone 

## hide .php extension 
# To externally redirect /dir/foo.php to /dir/foo 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC] 
RewriteRule^%1 [R,L,NC] 

## To internally redirect /dir/foo to /dir/foo.php 
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule^%{REQUEST_URI}.php [L] 

# e.g. example.com/foo will display the contents of example.com/foo.html 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}.html -f 
RewriteRule ^(.+)$ $1.html [L,QSA] 

的有沒有辦法讓這兩個在一個htaccess的共同努力文件?

回答

1

您在頂部有一個重定向規則,然後有兩組規則可以將php或html擴展添加到請求的末尾(如果存在這樣的文件)。然後你的其他規則做index.php路由。

有些事情你需要制定出來。因爲您的網址在請求中沒有cl_clone(例如,它們只是www.mydomain.com/about,沒有cl_clone),所以您的重寫基地爲/cl_clone,因爲這兩種情況在任何一種情況下似乎都不起作用。

所以你可能想要刪除它。

否則,您可以簡單地將index.php路由規則添加到您擁有的其他規則的最底部。您可能需要添加額外的調整,也許是:

RewriteRule ^([A-Za-z0-9-_]+)/?$ index.php?subclass=$1 [NC,L] 
RewriteCond %{REQUEST_URI} !index.php 
RewriteRule ^.* index.php [NC,L] 

或更改RewriteBase /cl_cloneRewriteBase /