Reputation: 311
I'm having some troubles with mod_rewrite.
On my index page (index.php) I show a blog and a single blog post page looks like this: http://www.mydomain.com/blog/post-title
mod_rewrite for this is:
RewriteRule ^blog/([A-Za-z0-9-]+)$ index.php?postslug=$1 [L]
This works like a charm.
But I also have another page called artists.php and the url should look like this: http://www.mydomain.com/artists/artist-name
mod_rewrite for this is:
RewriteRule ^artists/([A-Za-z0-9-]+)$ artists.php?artistslug=$1 [L]
This gives me a 500 internal server error and I have no clue why this happens...
Both index.php and artists.php are in the root of my website
.htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ^blog/([a-z0-9\-]+)$ index.php?postslug=$1 [L]
RewriteRule ^artists/([a-z0-9\-]+)$ artists.php?artistslug=$1 [L]
Upvotes: 0
Views: 4590
Reputation: 925
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [NC,OR]
RewriteCond %{REQUEST_FILENAME} -d [NC]
RewriteRule .* - [L]
RewriteRule ^blog/([-A-z0-9]+)$ index.php?postslug=$1
RewriteRule ^artists/([-A-z0-9]+)$ artists.php?artistslug=$1
Upvotes: 0
Reputation: 655129
Try this rule instead of your one with the two RewriteCond
:
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.php -f
RewriteRule ^(.*)$ $1.php [L]
I’ve tested it myself and %{REQUEST_FILENAME}
seems to contain the wrong value but -f
is evaluated to true anyhow.
Upvotes: 4
Reputation: 12683
The RewriteRule itself looks fine to me, check if the server error occurs if you access the artists.php file directly, without the URL rewriting taking place.
Upvotes: -1