Multiple Parameters & ACTUAL Redirection?

Discuss practical ways rearrange URLs using mod_rewrite.

Multiple Parameters & ACTUAL Redirection?

Postby superdevo » Tue Oct 20, 2009 11:02 am

Hello everyone,

I am trying to re-write and 301 redirect the URL "www.example.com/index.php?cat=345&art=1234567" to "www.example.com/345/1234567"

Also, I would like to re-write URLs with 3+ parameters, instead of just 2, such as in the URL "www.example.com/index.php?cat=345&art=1234567&artist=45"

I have some code I am using, but it is written for 2 parameters and does not redirect the re-written URL.

Could someone please tell me what I need to change or add to the following code to make it redirect and use more than 2 parameters:

Code: Select all
# Redirect two-parameter-based index.php¦html? or / URL request
# (with parameters in any order) to folder-based URL format, and
# force www to always be in URL:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(index\.(php¦html?))?(\?[^\ ]*)\ HTTP/ [NC]
RewriteCond %{QUERY_STRING} &?cat=([0-9]{3})&?
RewriteCond %1>%{QUERY_STRING} ^([^>]+)>([^&]*&)*art=([0-9]{7})&?
RewriteRule ^(index\.(php¦html?))?$ http://www.domain.com/%1/%3? [R=301,L]

# Rewrite URL request: www.domain.com/345/1234567 to internal
# path: /index.php?cat=345&art=1234567 to serve content:
RewriteRule ^([0-9]{3})/([0-9]{7})$ /index.php?cat=$1&art=$2 [L]


All help will be greatly appreciated.

Thank you
superdevo
 
Posts: 2
Joined: Mon Oct 19, 2009 10:10 pm

Postby richardk » Wed Oct 21, 2009 10:06 am

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^(.*&)?cat=([0-9]{3})(&.*)?$ [NC]
RewriteCond %1&%{QUERY_STRING} ^([^&]+)&(.*&)?art=([0-9]{7})(&.*)?$ [NC]
RewriteRule ^(index\.(php|html?))?$ http://www.example.com/%1/%3? [R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^(.*&)?cat=([0-9]{3})(&.*)?$ [NC]
RewriteCond %2&%{QUERY_STRING} ^([^&]+)&(.*&)?art=([0-9]{7})(&.*)?$ [NC]
RewriteCond %1&%3&%{QUERY_STRING} ^([^&]+)&(.*&)?artist=([0-9]+)(&.*)?$ [NC]
RewriteRule ^(index\.(php|html?))?$ http://www.example.com/%1/%2/%3? [R=301,L]

RewriteRule ^([0-9]{3})/([0-9]{7})/?$ /index.php?cat=$1&art=$2 [L]
RewriteRule ^([0-9]{3})/([0-9]{7})/([0-9]+)/?$ /index.php?cat=$1&art=$2&artist=$3 [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby superdevo » Sat Nov 14, 2009 8:28 pm

Thank you for the code you have provided richardK.

What would I add or change to your above code if I wanted to add a 4th parameter?

"www.example.com/index.php?cat=345&art=1234567&artist=45&type=92"

I think one more example including a 4th parameter may help me see a pattern of what needs to be changed everytime I am dealing with an additional parameter.

Thanks
superdevo
 
Posts: 2
Joined: Mon Oct 19, 2009 10:10 pm


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: Exabot [Bot] and 2 guests

cron