【问题标题】:mod_rewrite sometimes turns off?mod_rewrite 有时会关闭?
【发布时间】:2012-07-17 08:37:09
【问题描述】:

我在我的 .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 页面并阅读其内容,但有时重写模块会在未创建干净 URL 的情况下关闭,并且文章以以下 URL 打开:www.mydomain.com/index.php?article=1234

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

【问题讨论】:

    标签: .htaccess mod-rewrite


    【解决方案1】:

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

    【讨论】:

    • 嗯好吧,服务器上的某些设置可以阻止创建干净 url 的功能吗? ,因为它在大多数情况下都可以正常工作,但有时网站运行缓慢,然后链接打开为 www.mydomain.com/index.php?article=1234 我还有一个问题,请按照 google 处理干净的方式使用这种效果-网址?因为我不希望谷歌存档 un-clean-urls。
    猜你喜欢
    • 1970-01-01
    • 2010-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-27
    • 1970-01-01
    • 1970-01-01
    • 2013-12-12
    相关资源
    最近更新 更多