Htaccess将所有请求重定向到索引(不允许映像)Wamp服务器


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

我需要帮助。我在一个网站上工作,希望将所有请求重定向到索引文件,同时允许访问图像、css、javascript和其他非php脚本的文档。我正在使用本地服务器(WAMP)。我遇到的问题是,它将所有请求重定向到包括图像在内的索引文件。下面是我的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>

这不是你的目标吗?

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

您还应该在第一个重写规则中转义这些斜杠

感谢我已经弄清楚了,我刚刚修改了将第一个重写规则移动到重写条件之上,现在它工作正常。

<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>