问题
I want to create seo friendly url's for my website. I want to create it from .htaccess file. I have very less knowledge about .htaccess
I have following url http://www.testsite.com/index.php?dispatch=flowers_search.flowers_search_result&city=Pune&type=Carnation
I need to display url as follows, http://www.testsite.com/flowers/Pune/Carnation
Thanks
回答1:
http://www.generateit.net/mod-rewrite/
resulting in:
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /index.php?dispatch=flowers_search.flowers_search_result&city=$1&type=$2 [L]
回答2:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php?args=%{REQUEST_URI} [L]
</IfModule>
This will put your query string into a variable that you can use on your page as $_GET['args']
. So you call:
http://www.testsite.com/flowers/Pune/Carnation
but you're really displaying the page:
http://www.testsite.com/?args=flowers/Pune/Carnation
You can then take $_GET['args']
and parse it however you want like:
$args = explode('/', $_GET['args']);
array_shift($args); // this take an empty value off of the first item in the array
$dispatch = $args[0];
$city = $args[1];
$type = $args[2];
and so on.
回答3:
Just Try With the following :
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /index.php?dispatch=$1&city=$2&type=$3 [L]
I think this may help you to resolve your problem.
来源:https://stackoverflow.com/questions/12019022/how-to-write-seo-friendly-urls-using-htaccess