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 "" to ""

Also, I would like to re-write URLs with 3+ parameters, instead of just 2, such as in the URL ""

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?))?$ [R=301,L]

# Rewrite URL request: 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
Posts: 2
Joined: Mon Oct 19, 2009 10:10 pm

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

Code: Select all
Options +FollowSymLinks

RewriteEngine On

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

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?))?$ [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]
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?


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.

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

Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 4 guests