简体   繁体   English

RewriteCond%{REQUEST_FILENAME}!-f对.php文件不起作用

[英]RewriteCond %{REQUEST_FILENAME} !-f doesn't work for .php files

I have a symfony 2 website which requires all urls to be re-written to the document index. 我有一个symfony 2网站,该网站要求将所有URL重新写入文档索引。

Additionally, there are a number of completely independent "micro sites" which just run out of their own sub-folders in the web directory. 此外,还有许多完全独立的“微型站点”,它们在Web目录中用完了自己的子文件夹。 I need to add re-write exceptions for any urls that point to the microsite sub folders 我需要为指向微型站点子文件夹的所有URL添加重写例外

This is my .htaccess file: 这是我的.htaccess文件:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/(microsite1|microsite2|microsite3)(.*)$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ %{document_index} [QSA,L]
</IfModule>

This works for everything except .php files within the microsite folders, ie: 这适用于除微型站点文件夹内的.php文件以外的所有内容,即:

  • www.domain.com/microsite1/index.html ---works (displays index.html) www.domain.com/microsite1/index.html --- works(显示index.html)
  • www.domain.com/microsite2/ ---works (displays index.php) www.domain.com/microsite2/ --- works(显示index.php)
  • www.domain.com/microsite2/contact.php --- doesn't work (displays symfony route not found error) www.domain.com/microsite2/contact.php --- 不起作用 (显示未找到symfony路由错误)

aditionally: 的方法,另外:

  • www.domain.com/microsite2/images/ ---successfully displays directory listing www.domain.com/microsite2/images/-成功显示目录列表
  • www.domain.com/microsite2/images/image.jpg --- successfully displays image www.domain.com/microsite2/images/image.jpg ---成功显示图像

You might need to change your apache config to something like this: 您可能需要将apache配置更改为以下内容:

<VirtualHost *:80>
    ServerName server-name
    DocumentRoot /var/www/path/to/document/root
    <Location />
            RewriteEngine on
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule !\.(js|ico|gif|jpg|png|css)$ /index.php
    </Location>
</VirtualHost>

Paying close attention to the last RewriteRule... 密切注意最后的RewriteRule ...

Keep it simple - add this rule to your .htaccess: 保持简单-将此规则添加到您的.htaccess文件中:

RewriteCond %{REQUEST_URI} ^/microsite1 [OR]
RewriteCond %{REQUEST_URI} ^/microsite2 [OR]
RewriteCond %{REQUEST_URI} ^/microsite3
RewriteRule ^.*$ - [NC,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM