htaccess 3级目录重写规则

时间:2014-11-30 09:47:29

标签: .htaccess

我的htaccess文件有什么问题?我希望能够像这样访问我的网站: site.com,site.com/en,site.com/en/dir,site.com/en/dir/subdir。但是我得到404错误 (只有site.com指向index.php,网址如site.com/en或site.com/en/dir返回404错误.mod_rewrite已启用)

RewriteEngine on 
Options -Indexes
Options +FollowSymlinks

AddDefaultCharset utf-8

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([a-zA-Z0-9_]+)(/?)$ index.php?route=$1 [QSA,L]
RewriteRule ^([a-zA-Z0-9_]+)(/?)([a-zA-Z0-9_\-]+)(/?)$ index.php?route=$1&subroute=$3    [QSA,L]
RewriteRule ^([a-z]+)(/?)([a-zA-Z0-9_]+)(/?)([a-zA-Z0-9_\-]+)(/?)$ index.php?language=$1&route=$3&subroute=$5 [QSA,L]

2 个答案:

答案 0 :(得分:1)

确保启用.htaccess和mod_rewrite。启用后,您可以使用:

AddDefaultCharset utf-8
Options +FollowSymlinks -Indexes
RewriteEngine on 
RewriteBase /

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]

RewriteRule ^(\w+)/?$ index.php?route=$1 [QSA,L]
RewriteRule ^(\w+)(/?)([\w-]+)/?$ index.php?route=$1&subroute=$2 [QSA,L]
RewriteRule ^([a-z]+)/(\w+)/([\w-]+)/?$ index.php?language=$1&route=$2&subroute=$3 [QSA,L]

答案 1 :(得分:0)

原因是在记事本6.5.5中删除了没有dom编码的utf8中的换行符 在线htaccess测试人员帮助找到了问题