简体   繁体   中英

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. I have some subdirectories and files in the /news directory.

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.

My current .htaccess looks like:

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

How to use the same clean path as existing directory in this case?

Following rule should work for you in root .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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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