URL Rewriting for a CMS

Discuss practical ways rearrange URLs using mod_rewrite.

Postby Haran » Tue Mar 24, 2009 3:58 am

Thanks richardk,
you have been really helpful :)

I've one more question, it happens sometime that a variable is empty and I get a double slash
Code: Select all
http://haransite.com/snapshot/guide/ITALY/Molise//Campobasso/Articles/001G4NJNBDJCVJ/


In this case is there a way to replace the double slash with something else? For example:
Code: Select all
http://haransite.com/snapshot/guide/ITALY/Molise/Molise/Campobasso/Articles/001G4NJNBDJCVJ/


TIA :)
Haran
Haran
 
Posts: 16
Joined: Sat Feb 21, 2009 1:09 pm

Postby richardk » Tue Mar 24, 2009 2:33 pm

Will it always be the same value? (Molise)
Will there ever be more than one double slash in a URL?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Haran » Wed Mar 25, 2009 9:41 am

richardk wrote:Will it always be the same value? (Molise)
Will there ever be more than one double slash in a URL?


If possible I'd like to fill the empty value with the previous variable, if too complicated, a standard value is ok as well.

Double slashes are not usual and appear just once in a single URL.


Thanks,
Haran
Haran
 
Posts: 16
Joined: Sat Feb 21, 2009 1:09 pm

Postby richardk » Wed Mar 25, 2009 3:38 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{THE_REQUEST} \ /(.+/)?([^/]+)/(/[^\ ]*)\  [NC]
RewriteRule .* /%1%2/%2%3 [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Haran » Mon Mar 30, 2009 4:00 am

Hi richardk,
sorry if I keep bothering you.

What if I choose to make this subdir/variable optional? Show it if exist otherwise don't put anything?


Thanks,
Haran
Haran
 
Posts: 16
Joined: Sat Feb 21, 2009 1:09 pm

Postby richardk » Mon Mar 30, 2009 6:21 am

Is the optional sub directory always in the same place?
What is your current working mod_rewrite?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Haran » Mon Mar 30, 2009 9:10 am

Yes, the optional variable is always in the same position:
Code: Select all
http://haransite/EN/ITALY-holiday-guide/Umbria-/Todi/Amongst%20Umbria%27s%20towns%2C%20Todi%20is%20ideal/001G3G5SV9CJXZMJ-3FQW5UQILGIS

and here is the rule:
Code: Select all
RewriteRule ^([^/]+)/([^/]+)-holiday-([^/]+)/([^/]+)(-([^/]+))/([^/]+)/([^/]+)/([^/]+)-([^/]+)$ /public/snapshot.cgi?cat=$3&area1=$2&area2=$4&area3=$6&des=$7&pname=$8&cdo=$9&loc=$10&lng=$1 [L]


I'd like to remove area3=$6 when its value is not specified.

With the actual rule I receive a 404 error when $6 is not present (like in the sample URL).


Haran
Haran
 
Posts: 16
Joined: Sat Feb 21, 2009 1:09 pm

Postby richardk » Mon Mar 30, 2009 2:03 pm

The entire mod_rewrite.

You can't have $10.

Try
Code: Select all
RewriteRule ^([^/]+)/([^/]+)-holiday-([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)-([^/]+)$ /public/snapshot.cgi?cat=$3&area1=$2&area2=$4&des=$5&pname=$6&cdo=$7&loc=$8&lng=$1 [L]
RewriteRule ^([^/]+)/([^/]+)-holiday-([^/]+)/([^/]+)-([^/]+)/([^/]+)/([^/]+)/([^/]+)-([^/]+)$ /public/snapshot.cgi?cat=$3&area1=$2&area2=$4&area3=$5&des=$6&pname=$7&cdo=$8&loc=$9&lng=$1 [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Haran » Tue Mar 31, 2009 2:21 am

Hi richardk,
in the first rule you have completely removed the variable which is very important for me, it contains good keywords.

Using the second one I receive a 404 error. :(


Haran
Haran
 
Posts: 16
Joined: Sat Feb 21, 2009 1:09 pm

Postby richardk » Tue Mar 31, 2009 8:08 am

What URL produces a 404 error?

You are supposed to replace the one rule you posted with both of those rules.

Post your entire mod_rewrite.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

PreviousNext

Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 11 guests

cron