[英]Clean path with the same name as a directory
I have a directory /news within the root directory and I have a /news clean path too. 我在根目录中有一个目录/ news,我也有一个/ news clean路径。 I have some subdirectories and files in the /news directory.
我在/ news目录中有一些子目录和文件。
I need to support the clean path /news (with same extra $_GET parameters sometimes) and allow to linking to real files and subdirectories within the real /news directory. 我需要支持干净的路径/ news(有时带有相同的$ _GET参数),并允许链接到真实/ news目录中的真实文件和子目录。
My current .htaccess looks like: 我当前的.htaccess如下所示:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} /news/?$ [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]
but there are some issues with ajax requests (there is no problem on casual user requests) to the /news path if there are some GET parameters and it always adds slash at the end of the path, for example I enter example.com/news, so it redirects to example.com/news/. 但是,如果有一些GET参数,则对/ news路径的ajax请求有一些问题(临时用户请求没有问题),并且总是在路径末尾添加斜杠,例如,我输入example.com/news ,因此它将重定向到example.com/news/。
How to use the same clean path as existing directory in this case? 在这种情况下,如何使用与现有目录相同的干净路径?
Following rule should work for you in root .htaccess: 以下规则应该在根.htaccess中为您工作:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/news/?$ [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
Make sure there is no /news/.htaccess
to override this. 确保没有
/news/.htaccess
来覆盖它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.