rewrites are messing up my redirects

Using mod_rewrite to handle various content issues

rewrites are messing up my redirects

Postby zig » Wed Dec 19, 2007 11:40 pm

Great forum, I know where to come to learn all this now! ;)

My new blog (Textpattern) rewrites are messing up my redirects. Old pages are from an old messy URL script.
I've tried for hours with no luck. I commented within the redirects whats going on.
Sure could use some help...

Be happy to send a Paypal as thanks too :)

Code: Select all
#DirectoryIndex index.php index.html
#Options +FollowSymLinks -MultiViews
#Options -Indexes

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

<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteCond %{REQUEST_FILENAME} -f [OR]
   RewriteCond %{REQUEST_FILENAME} -d
   RewriteRule ^(.+) - [PT,L]
   RewriteRule ^(.*) index.php
</IfModule>
#php_value register_globals 0

Redirect permanent /ask-bob.php http://mydomain.com/ask-bob/ WORKS
but
Redirect permanent /ask-bob.php?ID=6 http://mydomain.com/ask-bob/new-page-title
Resolves to http://mydomain.com/ask-bob/?ID=6
&
Redirect permanent /place-to-be.php http://mydomain.com/new-section/ WORKS
but
Redirect permanent /place-to-be.php?placeID=2 http://mydomain.com/new-section/new-page-title
Resolves to http://mydomain.com/new-section/?ID=2


I have about 50 pages to redirect in the 2 sections above, plus keep my blog happy.
It acts like theres a [QSA] but there isn't one???

Thanks again ;)
zig
 
Posts: 6
Joined: Wed Dec 19, 2007 7:26 pm

Postby richardk » Thu Dec 20, 2007 3:06 am

Try
Code: Select all
Options +FollowSymLinks

Redirect 301 /ask-bob.php http://mydomain.com/ask-bob/?
Redirect 301 /ask-bob.php?ID=6 http://mydomain.com/ask-bob/new-page-title?
Redirect 301 /place-to-be.php http://mydomain.com/new-section/?
Redirect 301 /place-to-be.php?placeID=2 http://mydomain.com/new-section/new-page-title?

<IfModule mod_rewrite.c>
   RewriteEngine On

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

   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule .* index.php [QSA,L]
</IfModule>
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby zig » Thu Dec 20, 2007 7:46 am

Hey Richard, sure appreciate your help. ;)

OK, thats an improvement!

Code: Select all
Redirect 301 /place-to-be.php?placeID=2 http://mydomain.com/new-section/new-page-title?

Is resolving to http://mydomain.com/new-section/?


At least no query string. 8)

Looks like'ol Yahoo grabbed a couple of the malformed ones too, have a 503 up now temporarily.
Probably need a "anything with a ? is [G]" rule now too.

This is turning out to be a lot trickier than I ever imagined?
Interested in a little side work? :)
zig
 
Posts: 6
Joined: Wed Dec 19, 2007 7:26 pm

Postby richardk » Thu Dec 20, 2007 10:40 am

First try removing the ?s from the Redirects.

If that doesn't work, you'll probably need to do it with mod_rewrite
Code: Select all
# /ask-bob.php --> /ask-bob/
RewriteRule ^ask-bob\.php$ /ask-bob/new-page-title? [R=301,L]

# /ask-bob.php?id=6 --> /ask-bob/new-page-title
RewriteCond %{QUERY_STRING} ^(.*&)?id=6(&.*)?$ [NC]
RewriteRule ^ask-bob\.php$ /ask-bob/new-page-title? [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby zig » Thu Dec 20, 2007 11:22 am

Woohoo! I tested ?ID=6 & it worked ;)

Is there a way to use a single RewriteCond with multiple RewriteRules?
The ask-bob string values run from ?ID=6-65 & the place-to-be from ?placeID=2-48

or do I need a RewriteCond for each RewriteRule?

Would really cut down on lines of code if I could get away with 2 RewriteConds

Thank you VERY much ;)
zig
 
Posts: 6
Joined: Wed Dec 19, 2007 7:26 pm

Postby richardk » Thu Dec 20, 2007 11:31 am

No, not unless you have access to the httpd.conf file to define a Rewritemap.

It might be better to create those PHP files and do a redirect with PHP instead, for example
Code: Select all
<?php

$redirect = array();
$redirect[6] = 'title-of-6';
$redirect[7] = 'title-of-7';
$redirect[8] = 'title-of-8';

if(isset($_GET['id']) && !empty($_GET['id']) && is_numeric($_GET['id']) && isset($redirect[$_GET['id']]))
{
  header('Location: http://' . getenv('HTTP_HOST') . '/ask-bob/' . $redirect[$_GET['id']], true, 301);
}
else
{
  // Redirect to your homepage.
  header('Location: http://' . getenv('HTTP_HOST') . '/', true, 301);
}
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby zig » Thu Dec 20, 2007 12:53 pm

Well, I have all the ask-bob's working now. ;)

Not the /new-section/ though, I tried to change ask-bob but its not working?
Getting 404's

Code: Select all
RewriteCond %{QUERY_STRING} ^(.*&)?placeID=2(&.*)?$ [NC]
RewriteRule ^place-to-be\.php$ /new-section/new-place-to-be-page? [R=301,L]

Redirect permanent /place-to-be.php?placeID=2 http://mydomain.com/new-section/new-place-to-be-page
Getting 404


Is the placeID being different the problem? I tried lower case placeid= & just id= too. Looks so close, I thought I had it?
zig
 
Posts: 6
Joined: Wed Dec 19, 2007 7:26 pm

Postby zig » Thu Dec 20, 2007 1:07 pm

One other weird thing, does -n- do something?

Code: Select all
For the main directory, this works.
RewriteRule ^ask-bob\.php$ /ask-bob/? [R=301,L]

This doesn't though
RewriteRule ^rock-n-roll\.php$ /rock-n-roll/? [R=301,L]


EDIT: I used 301's instead of Rewrites for a couple of these & are now working. Still wondering why the Rewrites didn't work though?
Have about 10 left with the issue in the post above & I think I have it whupped?

You're a lifesaver ;)
How can I get your Paypal?
PM it to me if you can?
zig
 
Posts: 6
Joined: Wed Dec 19, 2007 7:26 pm

Postby zig » Thu Dec 20, 2007 3:18 pm

OK, between a combo of htaccess Rewrites, Redirects & PHP Redirects, I got'er whupped! ;)

Last thing is [G]ing all malformed urls that got indexed, I think only a couple did. Need to nip'em in the bud though.
I saw a Yahoo thread about exactly that.
If I need help, I'll post there.

Send me that Paypal ;)

cheers
zig
 
Posts: 6
Joined: Wed Dec 19, 2007 7:26 pm

Postby richardk » Fri Dec 21, 2007 10:37 am

One other weird thing, does -n- do something?

Not as far as i know. Did those files exists? It might work if you use
Code: Select all
Options +FollowSymLinks -MultiViews
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Content

Who is online

Users browsing this forum: No registered users and 1 guest

cron