.htaccess issue, existing .php files and search.php

Question!

I'm new to playing with .htaccess for nicely formatted urls and I'm just not sure I'm doing it right.

My current .htaccess file looks like this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^search/(.*) search.php?query=$1 [L]
RewriteRule !\.(gif|jpg|ico|css|js|txt|xml|png|swf)$ index.php

What I want is for mysite.com/home/56/page-title to go to index.php where I filter out the number and load the correct index page, which works fine.

Before that, I want to check if the url is pointing at search.php, and if so redirect to mysite.com/search/the-search-term, this also works fine.

What isn't working is if I try to visit a specific .php file say mysite.com/control_panel.php - it just takes me to index.php, but I thought that the following line stopped that from happening?

RewriteCond %{REQUEST_FILENAME} !-f

If someone could explain it to me that would be great :)

Thanks!

By : bbeckford


Answers

1. Order of rules matters

2. RewriteCond directives will only be applied to the ONE RewriteRule that follows it. If you need to apply the same conditions to multiple rules you have to write them multiple times or change the rewrite processing logic (multiple approaches available).

Try this one:

RewriteEngine On

RewriteRule ^search/(.*) search.php?query=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(gif|jpg|ico|css|js|txt|xml|png|swf)$ index.php [L]
By : LazyOne


This video can help you solving your question :)
By: admin