Dorian_gd
Dorian_gd

Reputation: 181

.htaccess only one RewriteRule is not working

I have a problem with only one page on the RewriteRule htaccess:

the page http://www.snes-fr.net/staff.html is not working (404) but ALL other are.

staff.php is in the folder: http://www.snes-fr.net/pages/staff.php

.htaccess line: RewriteRule ^staff\.html$ index.php?page=staff [L]

but this link is not working: http://www.snes-fr.net/staff.html this one is working: http://www.snes-fr.net/cgu.html

RewriteRule ^cgu\.html$ index.php?page=cgu [L]

The code which show the page

$page = @htmlspecialchars($_GET['page'], ENT_QUOTES);
    if(is_file('pages/'.$page.'.php'))
       {
       require('pages/'.$page.'.php');
       }

Do you have any clue? Thank you

EDIT: htaccess:

SetEnv PHP_VER 5_4
ErrorDocument 404 http://www.snes-fr.net/404.html
RewriteEngine on
Options +FollowSymlinks

SetEnv REGISTER_GLOBALS 1
SetEnv MAGIC_QUOTES 0


RewriteCond %{HTTP_REFERER} decerto\.fr [NC]
RedirectMatch seeother ^/dossier-super-nintendo_([0-9]+)_(.*)\.html$ http://www.snes-fr.net/tests.html 
#REECRITURE


RewriteRule ^staff\.html$ index.php?page=staff [L]
RewriteRule ^cgu\.html$ index.php?page=cgu [L]
RewriteRule ^contact\.html$ index.php?page=contact [L]
RewriteRule ^404\.html$ index.php?page=404 [L]
RewriteRule ^index\.html$ index.php [L]

...

All I have are working RewriteRule after !

Upvotes: 0

Views: 582

Answers (3)

anubhava
anubhava

Reputation: 786091

I believe this is because of MultiViews

As per Officla Manual:

Using a 'MultiViews' search, where the server does an implicit filename pattern match and chooses from among the results.

Try turning it off on top of your .htaccess:

Options +FollowSymLinks -MultiViews

Upvotes: 0

Merijn Den Houting
Merijn Den Houting

Reputation: 199

Wouldn't it be easier to use one line of code for all pages? Something like

RewriteRule ^(.*)\.html$ index.php?page=$1 [L]

Upvotes: 1

Aurelien Maigret
Aurelien Maigret

Reputation: 402

Your line is correct, the problem has to come from elsewhere in the htaccess. Can you share the rest of the file please ?

However, be careful, you should not use htmlspecialchars for protect your require. You can rather use the function basename : http://php.net/manual/en/function.basename.php

Upvotes: 0

Related Questions