简体   繁体   中英

How do I link correctly when a file(extensions removed) and a folder have the same name?

So here's the problem I've been facing.

I have to link to a file which has the same name as a folder on my server. Normally it wouldn't have been a problem, but since I have removed extensions it hasnt been working.

The file: privacy-policy.php Folder: privacy-policy

I have removed the .php extension using .htaccess, using the code which I will list below.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

When I click on the link hxxp://domain.com/privacy-policy it takes me to hxxp://domain.com/privacy-policy/ which is the folder. I want this link to take me to the file hxxp://domain.com/privacy-policy of which the extension have been removed.

I tried turning off DirectorySlash but it din't work.

Any help in this regard would be appreciated. Regards, Vinith Almeida

  1. You need DirectorySlash Off .
  2. Remove first RewriteCond

Your rule will be like this:

DirectorySlash Off

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]

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