Reputation: 5123
I have this working htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^test/([0-9]+)/?$ test.php?id=$1 [L]
my question for this if I have that rule on my htaccess how can I load php file that have no .php extension.
I add this to my htacess
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
It works fine http://localhost/myprojectfolder/account
but this will not work anymore http://localhost/myprojectfolder/1
how can I make them both working ?
Thank you in advance.
Upvotes: 2
Views: 623
Reputation: 24448
If you are using this URL http://localhost/myprojectfolder/1
as in your other question. Then test
shouldn't even be in the first rule. Then you can just make sure the file exists.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)/?$ test.php?id=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Upvotes: 2
Reputation: 143856
Try adding another condition to your php extension rule:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
that ensures that when you add the .php
extension, it actually points to a file that exists.
Upvotes: 3