SEO Friendly URL Rewrite

Discuss practical ways rearrange URLs using mod_rewrite.

SEO Friendly URL Rewrite

Postby aksm4783 » Wed Jun 11, 2008 1:40 pm

Hi,

I have questions about the URL rewrite. Currently, I have the following rules setup in my .htaccess file.

Code: Select all
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /brand\.php.*\ HTTP/
RewriteRule ^brand\.php$ http://www.computersox.com/brand/%1/ [R=301,L]

RewriteRule ^brand/([A-Za-z0-9-]+)$ http://www.computersox.com/brand/$1/ [R=301,L]

RewriteRule ^brand/([_0-9+a-z-A-Z]+)/$ brand.php?brand=$1&search=$1&allwords=on [L]

The first one is I want to transform parameterized URL to SEO Friendly URL. I know it is not working now.

e.g.
http://www.computersox.com/brand.php?brand=Sony&search=sony&allwords=on
TO
http://www.computersox.com/brand/Sony/
(All I need is the parameter for Brand)

The second one is to add the / at the end of URL
The third one is to rewrite SEO url to Parameterized URL.

Currently, the last 2 rules are working, but the first rule I don't know how to make it work.

Any helps will greatly appreciated.

Thank you very much for reading this post.

Andrew
aksm4783
 
Posts: 2
Joined: Wed Jun 11, 2008 1:30 pm

Postby richardk » Wed Jun 11, 2008 3:19 pm

With %{QUERY_STRING}
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*&)?brand=([^&]+)(&.*)?$ [NC]
RewriteRule ^brand\.php$ http://www.computersox.com/brand/%2/? [NC,R=301,L]

RewriteRule ^brand/([A-Za-z0-9-]+)$ http://www.computersox.com/brand/$1/ [R=301,L]

RewriteRule ^brand/([_0-9+a-z-A-Z]+)/$ brand.php?brand=$1&search=$1&allwords=on [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Friendly URLs with Mod_Rewrite

Postby aksm4783 » Thu Jun 12, 2008 2:34 pm

Code: Select all
   RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /brand\.php\?brand\=(.*)\&search\=(.*)\&allwords\=(.*)\ HTTP/
   RewriteRule ^brand\.php$ http://www.computersox.com/brand/${tolower:%1}/? [R=301,L]

   # Upper or Lower Letter without backslashe
   RewriteRule ^brand/([a-zA-Z]+)$ http://www.computersox.com/brand/${tolower:$1}/ [R=301,L]

   # Upper Letter Only
   RewriteRule ^brand/([A-Z]+)/$ http://www.computersox.com/brand/${tolower:$1}/ [R=301,L]

   # Mixed Upper and Lower Letters
[b](Need Code here)[/b]

   RewriteRule ^brand/([a-z]+)/$ brand.php?brand=${tolower:$1}&search=${tolower:$1}&allwords=on [L]


Do you know how to write the syntax that capture the mixed of upper and lower case without falling into the endless loop?

Write now the syntax can write the following to SEO friend URL

http://www.computersox.com/brand.php?br ... llwords=on
http://www.computersox.com/Sony
http://www.computersox.com/sony
http://www.computersox.com/SoNy

to

http://www.computersox.com/sony/

BUT for URL like http://www.computersox.com/SoNy/
I can't rewrite it to
http://www.computersox.com/sony/

Any help will be appreciate.

Thanks.
aksm4783
 
Posts: 2
Joined: Wed Jun 11, 2008 1:30 pm

Postby richardk » Fri Jun 13, 2008 2:35 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*&)?search=[^&]+(&.*)?$ [NC]
RewriteCond %{QUERY_STRING} ^(.*&)?allwords=[^&]+(&.*)?$ [NC]
RewriteCond %{QUERY_STRING} ^(.*&)?brand=([^&]+)(&.*)?$ [NC]
RewriteRule ^brand\.php$ http://www.computersox.com/brand/${tolower:%1}/? [NC,R=301,L]

RewriteRule ^brand/([a-z]+)$ http://www.computersox.com/brand/${tolower:$1}/ [NC,R=301,L]

# At least one upper-case letter.
RewriteRule ^brand/([a-zA-Z]*[A-Z][a-zA-Z]*)/$ http://www.computersox.com/brand/${tolower:$1}/ [R=301,L]

RewriteRule ^brand/([a-z]+)/$ brand.php?brand=$1&search=$1&allwords=on [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 13 guests

cron