我在.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
页面并阅读其内容,但有时重写模块会关闭,而不会创建干净的网址,文章会打开并显示以下网址:www.mydomain.com/index.php?article=1234
答案 0 :(得分:0)
您的规则中没有任何内容导致网址显示为www.mydomain.com/index.php?article=1234
。无论您打开文章的链接是什么,都可能无法生成干净的URL。