简体   繁体   English

htaccess将所有请求重定向到索引(不允许图像)Wamp Server

[英]Htaccess redirect all requests to index (does not allow images) Wamp Server

Please I need a help. 请我帮忙。 I am working on a site and wants to redirect all requests to an index file while allowing access to images, css, javascripts and other documents that are not php scripts. 我在一个网站上工作,希望将所有请求重定向到索引文件,同时允许访问图像,CSS,JavaScript和非PHP脚本的其他文档。 I am working on a local server (WAMP). 我正在本地服务器(WAMP)上工作。 The problem I have is that it redirects all requests to the index file including images. 我的问题是它将所有请求重定向到包括图像的索引文件。 Below is my htaccess rule. 以下是我的htaccess规则。

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteBase /myapp
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(\d{4})/(0?[1-9]|1[0-2])/([^/]+)/?$ app/$1-$2/$3 [R=301,L]
RewriteRule ^(.*)$ index.php [L]
</IfModule>

Is this not what you're aiming for? 这不是您的目标吗?

RewriteRule ^(.*\.php)$ index.php [L]

You should also escape those slashes in your first rewrite rule 您还应该在第一个重写规则中转义那些斜线

Thanks I have figured it out, I just modified the moved the first rewrite rule above the rewrite condition and it now working fine. 谢谢,我已经弄清楚了,我刚刚修改了第一个重写规则,使其超过了重写条件,现在可以正常工作了。

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteBase /myapp
RewriteRule ^(\d{4})/(0?[1-9]|1[0-2])/([^/]+)/?$ app/$1-$2/$3 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php [L]
</IfModule>

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

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