mod_rewrite有时会关闭?

时间:2012-07-17 08:37:10

标签: .htaccess mod-rewrite

我在.htaccess文件中使用mod_rewrite来制作更清晰的URL。我有两个目录(subdir1subdir2),它们是在根目录中创建的文件夹。它们不是子域。 .htaccess文件位于三个目录中:root,subdir1subdir2

以下.htaccess文件位于根目录:

Options All -Indexes
ErrorDocument 404 /404.php
FileETag MTime Size

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/(subdir1|subdir2)(/.*)?$ [NC]
RewriteCond %{REQUEST_URI} ^(.*)?$ [NC]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ /subdir1/ [R=301,QSA,L]

RewriteRule ^(.*)(\.html|\.htm)$ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ index.php [L]
</IfModule>

,这个位于subdir1目录:

Options All -Indexes
ErrorDocument 404 /404.php
FileETag MTime Size

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /subdir1/

RewriteRule ^(.*)(\.html|\.htm)$ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ index.php [L]
</IfModule>

一切都很好。我可以浏览www.mydomain.com/subdir1/1234-myaritcle.html页面并阅读其内容,但有时重写模块会关闭,而不会创建干净的网址,文章会打开并显示以下网址:www.mydomain.com/index.php?article=1234

你能帮帮忙吗?问题的原因是什么? .htaccess文件有问题吗?

1 个答案:

答案 0 :(得分:0)

您的规则中没有任何内容导致网址显示为www.mydomain.com/index.php?article=1234。无论您打开文章的链接是什么,都可能无法生成干净的URL。