views:

502

answers:

4

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]
+1  A: 

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.

Gumbo
typo, changed it
Bundy
thanks this did the trick!
Bundy
A: 

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.

Aistina
I checked it and it works fine. Both artists.php and artists.php?artistslug=test work like they should
Bundy
A: 
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
Paul Janaway
A: 

Turn on:

RewriteLog /path/to/file.log
RewriteLogLevel 4
Question Mark