Redirecting static URLs

Discuss practical ways rearrange URLs using mod_rewrite.

Redirecting static URLs

Postby servantofgod » Fri Dec 05, 2008 10:20 am

First I must say thank you to Richardk for all your help. This is definitely the #1 place to come for rewrite help.

I want to rewrite all http://www.whatsshopping.com/subcategories_and_featured_products-pid-68-cid-509.php to http://www.whatsshopping.com/women_subcategories_and_featured_products-pid-68-cid-509.php

Basically pid-68 signifies that this url is for women's department pages. cid-###.php identifies the actual section of that departments page, so it will vary So any pages with subcategories_and_featured_products-pid-68 need to redirect to women_""

What is the correct method for this?
servantofgod
 
Posts: 22
Joined: Wed Oct 01, 2008 8:14 am
Location: Chicago

Postby richardk » Sat Dec 06, 2008 8:35 am

What is the current URL in the source of your page?
What URL to you want it the source of your page?
Do you have mod_rewrite for this already?
Do you want a visible redirect or for the new URL to work?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby servantofgod » Sat Dec 06, 2008 11:27 am

href="subcategories_and_featured_products.php?pid=<?PHP echo $getsub["topSection"];?>&cid=<?PHP echo $getsub["sectionID"];?>"

the [topSection] controls the main category, so if that value is 68, it will go to the women's category. If it is 1, it will go to the electronics category.

i have new pages for all the categories, for example, anything with the [topSection] value of 68 i need to invisibly redirect to: "women_subcategories_and_featured_products.php?pid=<?PHP echo $getsub["topSection"];?>&cid=<?PHP echo $getsub["sectionID"];?>"

Thanks
servantofgod
 
Posts: 22
Joined: Wed Oct 01, 2008 8:14 am
Location: Chicago

Postby richardk » Sat Dec 06, 2008 12:46 pm

You only answered one question
What URL to you want it the source of your page?
Do you have mod_rewrite for this already?
Do you want a visible redirect or for the new URL to work?


Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^[^/_]+_subcategories_and_featured_products-pid-([0-9]+)-cid-([0-9]+)\.php$ /subcategories_and_featured_products.php?pid=$1&cid=$2 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby servantofgod » Sat Dec 06, 2008 3:37 pm

Sorry, I misexplained, and forgot about the important question you asked. There are already rewrite rules:

RewriteRule ^subcategories_and_featured_products-pid-([0-9]+)-cid-([0-9]+)\.php$ /subcategories_and_featured_products.php?pid=$1&cid=$2 [QSA,L]


This changes dynamic to static. In order to give distinct meta tags to each subcategories page, I had to make 20 copies, and add the category name and underscore before subcategories_and_featured_products.php, I then add to apply the rewrite rule to all twenty categories:

RewriteRule ^women_subcategories_and_featured_products-pid-([0-9]+)-cid-([0-9]+)\.php$ /women_subcategories_and_featured_products.php?pid=$1&cid=$2 [QSA,L]
RewriteRule ^men_subcategories_and_featured_products-pid-([0-9]+)-cid-([0-9]+)\.php$ /men_subcategories_and_featured_products.php?pid=$1&cid=$2 [QSA,L]
RewriteRule ^biker_subcategories_and_featured_products-pid-([0-9]+)-cid-([0-9]+)\.php$ /biker_subcategories_and_featured_products.php?pid=$1&cid=$2 [QSA,L]
RewriteRule ^hiphop_subcategories_and_featured_products-pid-([0-9]+)-cid-([0-9]+)\.php$ /hiphop_subcategories_and_featured_products.php?pid=$1&cid=$2 [QSA,L]
RewriteRule ^electronics_subcategories_and_featured_products-pid-([0-9]+)-cid-([0-9]+)\.php$ /electronics_subcategories_and_featured_products.php?pid=$1&cid=$2 [QSA,L]
RewriteRule ^games_subcategories_and_featured_products-pid-([0-9]+)-cid-([0-9]+)\.php$ /games_subcategories_and_featured_products.php?pid=$1&cid=$2 [QSA,L]
RewriteRule ^phones_subcategories_and_featured_products-pid-([0-9]+)-cid-([0-9]+)\.php$ /phones_subcategories_and_featured_products.php?pid=$1&cid=$2 [QSA,L]
RewriteRule ^personal_subcategories_and_featured_products-pid-([0-9]+)-cid-([0-9]+)\.php$ /personal_subcategories_and_featured_products.php?pid=$1&cid=$2 [QSA,L]
RewriteRule ^mobile_subcategories_and_featured_products-pid-([0-9]+)-cid-([0-9]+)\.php$ /mobile_subcategories_and_featured_products.php?pid=$1&cid=$2 [QSA,L]
RewriteRule ^kids_subcategories_and_featured_products-pid-([0-9]+)-cid-([0-9]+)\.php$ /kids_subcategories_and_featured_products.php?pid=$1&cid=$2 [QSA,L]
RewriteRule ^home_subcategories_and_featured_products-pid-([0-9]+)-cid-([0-9]+)\.php$ /home_subcategories_and_featured_products.php?pid=$1&cid=$2 [QSA,L]
RewriteRule ^ethnic_subcategories_and_featured_products-pid-([0-9]+)-cid-([0-9]+)\.php$ /ethnic_subcategories_and_featured_products.php?pid=$1&cid=$2 [QSA,L]
RewriteRule ^dvds_subcategories_and_featured_products-pid-([0-9]+)-cid-([0-9]+)\.php$ /dvds_subcategories_and_featured_products.php?pid=$1&cid=$2 [QSA,L]
RewriteRule ^computers_subcategories_and_featured_products-pid-([0-9]+)-cid-([0-9]+)\.php$ /computers_subcategories_and_featured_products.php?pid=$1&cid=$2 [QSA,L]
RewriteRule ^collectibles_subcategories_and_featured_products-pid-([0-9]+)-cid-([0-9]+)\.php$ /collectibles_subcategories_and_featured_products.php?pid=$1&cid=$2 [QSA,L]
RewriteRule ^cameras_subcategories_and_featured_products-pid-([0-9]+)-cid-([0-9]+)\.php$ /cameras_subcategories_and_featured_products.php?pid=$1&cid=$2 [QSA,L]
RewriteRule ^books_subcategories_and_featured_products-pid-([0-9]+)-cid-([0-9]+)\.php$ /books_subcategories_and_featured_products.php?pid=$1&cid=$2 [QSA,L]
RewriteRule ^auto_subcategories_and_featured_products-pid-([0-9]+)-cid-([0-9]+)\.php$ /auto_subcategories_and_featured_products.php?pid=$1&cid=$2 [QSA,L]
RewriteRule ^tv_subcategories_and_featured_products-pid-([0-9]+)-cid-([0-9]+)\.php$ /tv_subcategories_and_featured_products.php?pid=$1&cid=$2 [QSA,L]
RewriteRule ^security_subcategories_and_featured_products-pid-([0-9]+)-cid-([0-9]+)\.php$ /security_subcategories_and_featured_products.php?pid=$1&cid=$2 [QSA,L]


The problem is, there is still subcategories_and_featured_products.php, and subcategories_and_featured_products.php?pid=68&cid=72 is the same as women__subcategories_and_featured_products.php?pid=68&cid=72.

I need subcategories_and_featured_products.php?pid=68&cid=$1 to redirect to women_subcategories_and_featured_products.php?pid=68&cid=$2
servantofgod
 
Posts: 22
Joined: Wed Oct 01, 2008 8:14 am
Location: Chicago

Postby richardk » Sat Dec 06, 2008 4:53 pm

You should use
Code: Select all
RewriteRule ^women_subcategories_and_featured_products-pid-68-cid-([0-9]+)\.php$ /women_subcategories_and_featured_products.php?pid=68&cid=$1 [QSA,L]

not
Code: Select all
RewriteRule ^women_subcategories_and_featured_products-pid-([0-9]+)-cid-([0-9]+)\.php$ /women_subcategories_and_featured_products.php?pid=$1&cid=$2 [QSA,L]

or the name (women) will work with any PID. (And then you could remove "pid-68-".)

I need subcategories_and_featured_products.php?pid=68&cid=$1 to redirect to women_subcategories_and_featured_products.php?pid=68&cid=$2

Do you want to redirect /subcategories_and_featured_products.php?pid=68&cid=509, /subcategories_and_featured_products-pid-68-cid-509.php or both to redirect to /women_subcategories_and_featured_products-pid-68-cid-509.php?

Code: Select all
RewriteCond %{QUERY_STRING} ^(.*&)pid=68(&.*)?$ [NC]
RewriteCond %{QUERY_STRING} ^(.*&)cid=([0-9]+)(&.*)?$ [NC]
RewriteRule ^subcategories_and_featured_products\.php$ /women_subcategories_and_featured_products-pid-68-cid-%2.php? [R=301,L]

and/or
Code: Select all
RewriteRule ^subcategories_and_featured_products-pid-68-cid-([0-9]+)\.php$ /women-$0? [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby servantofgod » Sat Dec 06, 2008 5:27 pm

Thanks Richard, let me try each of those. I will let you know if I have anymore issues.
servantofgod
 
Posts: 22
Joined: Wed Oct 01, 2008 8:14 am
Location: Chicago


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: Google [Bot] and 22 guests

cron