Mod_rewrite忽略文件的扩展名

这是我的整个mod_rewrite条件:

<IfModule mod_rewrite.c> <Directory /var/www/> Options FollowSymLinks -Multiviews AllowOverride None Order allow,deny allow from all RewriteEngine On # force www. (also does the IP thing) RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} !^mysite\.com [NC] RewriteRule ^(.*)$ http://mysite.com/$1 [R=301,L] RewriteCond %{REQUEST_URI} ^system.* RewriteRule ^(.*)$ /index.php?/$1 [L] RewriteCond %{REQUEST_URI} ^application.* RewriteRule ^(.*)$ /index.php?/$1 [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)\.(\d+)\.(js|css|png|jpg|gif)$ $1.$3 [L] RewriteCond %{THE_REQUEST} /index\.(php|html) RewriteRule (.*)index\.(php|html)(.*)$ /$1$3 [r=301,L] RewriteCond %{REQUEST_URI} !^(/index\.php|/assets|/robots\.txt|/sitemap\.xml|/favicon\.ico) RewriteRule ^(.*)$ /index.php/$1 [L] # Block access to "hidden" directories or files whose names begin with a period. This # includes directories used by version control systems such as Subversion or Git. RewriteCond %{SCRIPT_FILENAME} -d [OR] RewriteCond %{SCRIPT_FILENAME} -f RewriteRule "(^|/)\." - [F] </Directory> </IfModule> 

假设只允许访问mysite.com(/index.php//assets//robots.txt|/sitemap.xml|/favicon.ico)

错误被注意到:mysite.com/sitemap vs mysite.com/sitemap.xml这两个地址都parsing为xml文件,而第一个url应该parsing为mysite.com/index.php/sitemap ***

出于某种原因,mod_rewrite完全忽略了缺less扩展。 这听起来像是一个Multiviews问题,所以我禁用Multiviews,它仍然在继续。

***然后一个不同的规则最终将index.php出来,我有另一个问题与一个额外的“/”被留下时,发生这种情况。

这个httpd文件是为我的codeigniter php框架设置的

答:我发现这个问题,事实certificate,即使我在httpd.conf文件中禁用了Multiviews,它们仍然在/ etc / apache2 / sites-available / default中启用,并且还在/ etc / apache2 / sites – 可选/默认的SSL

这双:

 RewriteCond %{REQUEST_URI} !^(/index\.php|/assets|/robots\.txt|/sitemap\.xml|/favicon\.ico) RewriteRule ^(.*)$ /index.php/$1 [L] 

以不同的方式处理这两个URI。 /sitemap.xml与RewriteCond不匹配,并传递到文件系统。 /sitemap与RewriteCond匹配,并被重写为/index.php/sitemap

问题是:您的应用使用该URI做什么? 如果它findsitemap.xml文件并提供它,这将解释您所看到的行为。

当请求是/sitemap时,我确实看不到这些重写可以为/sitemap.xml服务。 validation请求是否通过您的应用程序运行的一种方法是创build一个新的日志文件,并设置您的应用程序追加到每行请求包含date,请求的URI和它计划服务(或它从哪个模块运行代码)。


您可能需要详细阐述“额外的斜线”问题,并提供一些示例。 我不太明白这个问题。

随着评论,我现在明白,斜线问题在这里:

 RewriteCond %{THE_REQUEST} /index\.(php|html) RewriteRule (.*)index\.(php|html)(.*)$ /$1$3 [r=301,L] 

为了摆脱额外的斜线,你只需要将其与你正在剥离的其他部分包括在一起:( index.php ):

 RewriteCond %{THE_REQUEST} /index\.(php|html) RewriteRule (.*)index\.(php|html)/(.*)$ /$1$3 [r=301,L]