Results 1 to 6 of 6
Jan 15, 2013, 06:35 #1
- Join Date
- Jun 2012
- London, United Kingdom, United Kingdom
- 0 Post(s)
- 0 Thread(s)
.htaccess to redirect to 404 Error Message rather than empty html.php page
Using a song database as an example, I am using the below code:-
.htaccess (placed in root directory, with 404.html.php in the ‘includes’ directory; ‘includes’ directory is also located in the root directory; and I am running server on Apache)
ErrorDocument 404 /includes/404.html.php Options +FollowSymLinks RewriteEngine on RewriteRule ^song/([0-9]*)/([-()a-z0-9]*)$ song/?song_id=$1&song_url=$2 [L,QSA] RewriteRule ^artist/([-()a-z0-9]*)$ artist/?artist_url=$1 [L,QSA]
The 404 works, i.e. when entering a URL such as:-
I could conduct a check at the start of the respective indexes for song and artist whether there is a match and if not then redirect to 404, else continue with the code.
But I am sure there must be a way that this can be done more simply and cleanly within the .htaccess file (I think using mod_write / RewriteCond), right?