Reputation: 1363
I'm trying to write an .htaccess file that will
a) when navigating to mysite.com/myusername (which is non existent) it will show the contents of mysite.com/dmp/temp/myusername
b) hide .php from the URL's
When going to mysite.com it however it shows me the contents of mysite.com/dmp/temp folder. If I add /index in front then it will work.
Everything is working as intended except that. How can I make sure users that simply navigate to mysite.com are served index.php (without actually writing /index/ or /index.php) and also not redirected to the /dmp/temp folder?
Code:
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %(REQUEST_URI) !^temp
RewriteRule ^(.*) dmp/temp/$1 [L]
Upvotes: 1
Views: 366
Reputation: 2148
Let's look at your two regular expressions:
^([^\.]+)$
and
^(.*)
First one: Match every query which do not contain . with length 1 or more.
Second: Match everything from length 0 or more.
So if you open http://mysite.com/
you have an empty query, and it's matched by the second regex. This means it tries to open dmp/temp/
.
Try changing the second regex from ^(.*)
to ^(.+)
. That means it will match only if you have a query of length 1 or more, and it will not match http://mysite.com/
. Hopefully, you then will go to standard behaviour, showing the index.* file according to server settings (in your case index.php)
Upvotes: 3