问题
I need to adopt the following scheme:
If the url contains any file/script reference, leave that without rewriting
example.com/index.php ---> leave without rewriting url
If the url doesn't contains any references, something similar to:
example.com/some-thing-is-here
Re-write this to:
example.com?search.php?q=some-thing-is-here
I've found the solution for (1), but they all fail with (2). I am a newbie in htaccess, so need suggestions of how to do it, or a common general method to do it.
回答1:
The following should do what you ask. In addition to excluding files, it also excludes directories.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://www.example.com/search.php?q=$1 [R,L]
This article has some good information if you want to learn more about clean URLs.
Below are a few more resources if you want to learn more about .htaccess. Usage of this file is fairly complex. Once you know what it is capable of, I recommend you search on Google for the features you need, when you need them. There are a lot of things it does that you may never need.
- more .htaccess tips and tricks..
- Ultimate Htaccess File Sample
- URL Rewriting Guide
来源:https://stackoverflow.com/questions/13404934/make-url-pretty-with-htaccess