Reputation: 427
I would like to ask for help with the following: I have for example this rule mod_rewrite:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
I want to rewrite the URL www.x.cz/word to www.x.cz/word.php
This works, but problem arise in that case, if the URL is for example www.x.cz/word/xxx (shortly after another slash is some other text string). Then there is error 500. How could i solve this problem? (I would like the server to return 404 or do the same as referring to the URL www.x.cz/word.php - as if there was not the another string).
Thank you all for your willingness.
Upvotes: 1
Views: 66
Reputation: 784918
You can tweak your regex like this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^./]+) $1.php [L]
This will rewrite both /word/xxx
and /word/
to /word.php
Upvotes: 1