0

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

以下 .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 文件有问题吗?

4

1 回答 1

0

您的规则中没有任何内容导致 url 显示为www.mydomain.com/index.php?article=1234. 无论您使用何种链接打开文章,都可能不会生成干净的 URL。

于 2012-07-17T08:45:11.460 回答