3

I'm using a main index.php file to handle the most of requests, so my basic .htacess looks like this one:

RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.+)$ /index.php?page=$1 [L] 

But i've got some requests (like /signin or /signout) that needs to be handled directly from .php file with the same name (/signin.php and /signout.php).

So my .htaccess rules needs to be: "if %{REQUEST_FILENAME}.php does not exists redirect to /index.php?page=$1 else redirect to %{REQUEST_FILENAME}.php".

How can i do this?

1
  • By using a RewriteCond analog to the ones you already have in place to check whether or not an existing file is matched and a corresponding RewriteRule. Commented Oct 7, 2013 at 11:14

2 Answers 2

3

Replace your code with this:

RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^ %{REQUEST_URI}.php [L,NC] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME}.php !-f RewriteRule ^(.+)$ /index.php?page=$1 [L,QSA] 

This will send everything to /index.php that is not a valid file or directory and doesn't have a matching .php existing in your filesystem.

Sign up to request clarification or add additional context in comments.

1 Comment

It doesn't work. When i check an exsists file i got 404 not found error (/signin not redirect to signin.php).
-1

you could handle this in your index.php, just redirect every call on index.php. There you can readin all parameters given in URL.

$aParams = explode("/", $_SERVER["REQUEST_URI"]); 

Now you can handle all parameters and redirect if you need to.

1 Comment

Yes, but is not what i've asked.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.