Forum Moderators: phranque

Message Too Old, No Replies

Another redirect question

My script isn't working - need help

         

kenjas

7:28 pm on Apr 15, 2006 (gmt 0)

10+ Year Member



Hi. I just installed a new system on my website that creates search engine friendly URLs.

Now instead of /products.php?products_id=53, my site now converts that into /myproduct-p-53.html

The problem I've got is that I need to redirect calls to the old style page to the new style. The contribution I installed has a predefined script, but it is not working...

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)-p-(.*).html$ product_info.php?products_id=$2&%{QUERY_STRING}

Does anyone have any words of wisdom on why it isn't working or have ideas on what to try?

jdMorgan

2:44 am on Apr 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Where did you put this code in your directory structure?
Do you have any other working rewriterules on the server?
Please define "It doesn't work."
Please post relevant entries from your server error log.

Jim

kenjas

2:55 am on Apr 16, 2006 (gmt 0)

10+ Year Member



Yes, I have other rewrites that work. See the first set below. The ones below the [R=301,L] are the ones that don't work. When I say don't work, I'm expecting them to redirect attempts to load the old style pages to the new style pages. It allows me to load either page by typing the URL into my browser and it does not redirect me to the new page URL.

My .htaccess file is in the root of the domain. All the files referenced below are also in the root of the domain.

<IfModule mod_rewrite.c>

Options +FollowSymLinks
RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

RewriteRule ^(.*)-p-(.*).html$ product_info.php?products_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-c-(.*).html$ index.php?cPath=$2&%{QUERY_STRING}
RewriteRule ^(.*)-m-(.*).html$ index.php?manufacturers_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-pi-(.*).html$ popup_image.php?pID=$2&%{QUERY_STRING}
RewriteRule ^(.*)-t-(.*).html$ articles.php?tPath=$2&%{QUERY_STRING}
RewriteRule ^(.*)-a-(.*).html$ article_info.php?articles_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-pr-(.*).html$ product_reviews.php?products_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-pri-(.*).html$ product_reviews_info.php?products_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-i-(.*).html$ information.php?info_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-links-(.*).html$ links.php?lPath=$2&%{QUERY_STRING}

</IfModule>

[edited by: jdMorgan at 3:08 am (utc) on April 16, 2006]
[edit reason] Example.com [/edit]

jdMorgan

3:15 am on Apr 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> Now instead of /products.php?products_id=53, my site now converts that into /myproduct-p-53.html

How about testing one simple rule, and building up from there, rather than trying to get a big pile of rules to work all at once?


RewriteRule ^myproduct-p-([0-9]+)\.html$ /products.php?products_id=$1 [L]

Note that this code follows your verbal description, and not the sample code provided. Correct the pathnames as needed if the initial description was not correct.

Jim

kenjas

6:44 pm on Apr 16, 2006 (gmt 0)

10+ Year Member



I'm definitely not a regex or rewrite expert.

The rules I have above are published rules that were developed to accompany the seo friendly url contribution I installed. I haven't heard any complaining about it not working and it is a very popular contribution.

Can you help me disect what the rules are doing?

My understanding is that with the folllowing rule:

RewriteRule ^(.*)-p-(.*).html$ product_info.php?products_id=$2&%{QUERY_STRING}

the ^(.*)-p-(.*).html$ traps all pages that contain -p- and .html at the end and redirects the visitor to /product_info.php?products_id=(number passed in second field of the first part)&(whatever other variables are attached.

Is my interpretation correct? If so, it seems that if I put [mysite.com...]
It should rewrite the URL as [mysite.com...]

Is that correct?

jdMorgan

12:51 pm on Apr 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, that's correct. I was just trying to suggest a method to figure out why it doesn't work. The code has one minor flaw in each line, and may have more.

Jim