2

On my website, I have the following .htaccess file to have cleaner urls:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

This is working great when users type in hostname.com/filename, however it cancels the automatic redirect when users browse to hostname.com/map/, as the RewriteEngine automatically adds .php after the map, which gives the following result:

https://hostname.com/map/.php

Is there a way of using index.php as my index file being used when an user browse to a map instead of a file, while still having the same effect on users browsing to a file? So the expected outcome is based on 3 options:

1
  • I hope this is clear enough, it sounds a bit messy when I read the question again. I will try to improve it. Commented Dec 13, 2014 at 0:20

1 Answer 1

1

Normally if the configuration automatically use index.php you just have to add after RewriteCond %{REQUEST_FILENAME} !-f:

RewriteCond %{REQUEST_FILENAME} !-d
Sign up to request clarification or add additional context in comments.

3 Comments

Should I change the -f in my example to -d, in your example? Or add the condition with -d below the given example?
Thank you very much, it seems this fixed the issue! I'm using both conditions at the moment, as you suggested, however it seems to work with just changing the condition in my example to your version (with -d), is there any reason why this seems to work as well, or why I shouldn't use it?
With -f you test if one file exist with the same name and don't add .php in this case. With -d you test for directory. it's a good idea to test both. You can read that for more info: httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritecond

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.