Apache's rewrite module commands not working in .htaccess

Soldato
Joined
25 Feb 2003
Posts
3,263
Location
Stafford (uni)
Trying to run some rewrite module commands on the .htaccess file in the root directory of my web server.

This one is simply to point lyrics/artist/title directories to the php file, I get a 500 internal server error from it:
Code:
RewriteEngine On
RewriteRule ^lyrics/([0-9]+)/([0-9]+) lyrics.php?artist=$1&title=$2





This one is to point the root directory to index.php thus overwriting the auto index, I know I can do this with a simple redirect command but that shows the filename in the URL and I don't want to do that:

Code:
RewriteRule ^/$ index.php
This one just doesn't work and the site just uses the auto index of index.html.
 
Last edited:
Ah sorry what I meant was:
Code:
RewriteRule ^lyrics/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+) lyrics.php?artist=$1&title=$2

I think thats right, it's artist and title names that will be in there.

edit: Thanks for the solution to the index.

edit2: works now, thanks.
 
Last edited:
paulsheffII said:
You can use

RewriteRule ^lyrics/([^/]+)/([^/]+)$ /lyrics/$1/$2/ [R=301]
RewriteRule ^lyrics/([^/]+)/([^/]+)/?$ /lyrics.php?artist=$1&title=$2 [L]

If there's a unknown string

Ah ok thanks, that solves the problem of matching spaces in the regEx. Is it safe to accept any user input through the URL though? Or do I need a regEx expression at some point to only match [a-zA-Z0-9_] and spaces?

Ah I think this is what I need:
[a-zA-Z0-9_\s]

edit: Nope that doesn't work, guess i'll just have to go with the match unknown string expression even if it is more unsafe.
 
Last edited:
Back
Top Bottom