开发者

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

开发者 https://www.devze.com 2023-04-08 13:54 出处:网络
I\'m new to playing with .htaccess for nicely formatted urls and I\'m just not sure I\'m doing it right.

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!


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]
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号