absolutek
absolutek

Reputation: 97

How to write seo friendly url's using htaccess?

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

Upvotes: 1

Views: 3677

Answers (3)

John Peter
John Peter

Reputation: 2928

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.

Upvotes: 0

tptcat
tptcat

Reputation: 3961

<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.

Upvotes: 0

Wurstbro
Wurstbro

Reputation: 974

http://www.generateit.net/mod-rewrite/

resulting in:

RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /index.php?dispatch=flowers_search.flowers_search_result&city=$1&type=$2 [L]

Upvotes: 2

Related Questions