【发布时间】:2012-07-17 08:37:09
【问题描述】:
我在我的 .htaccess 文件中使用 mod_rewrite 来制作更清晰的 URL。我有两个目录(subdir1、subdir2),它们是在根目录中创建的文件夹。它们不是子域。 .htaccess 文件位于三个目录中:root、subdir1 和 subdir2。
以下 .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 页面并阅读其内容,但有时重写模块会在未创建干净 URL 的情况下关闭,并且文章以以下 URL 打开:www.mydomain.com/index.php?article=1234
你能帮忙吗?问题的原因是什么? .htaccess 文件有问题吗?
【问题讨论】:
标签: .htaccess mod-rewrite