2013-01-04 43 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 /