How to write seo friendly url's using htaccess?

浪子不回头ぞ 提交于 2019-12-23 03:52:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!