homepage Welcome to WebmasterWorld Guest from 38.107.191.80
register, login, search, glossary, subscribe, help, library, PubCon, announcements, recent posts, unanswered posts,
PubCon Media Partner
Home / Forums Index / The Webmaster World / Apache Web Server
Forum Library : Charter : Moderators: jdMorgan

Apache Web Server

    
Help 301 Redirect old asp site to PHP
Help 301 Redirect old asp site to PHP
russwittmann


#:3876092
 9:29 pm on Mar 21, 2009 (utc 0)

Hello,

I have an old site that was recently converted to a php (expression engine cms site) all the old content is gone and I need to redirect the pages to the proper place except i'm having issues with my 301 redirect...

the old url is [domain.com...]

the new url is [domain.com...]

the redirect method I tried was

Redirect 301 /contentpage.asp?ContentID=7 [domain.com...]

but that is not working and im assuming it has something to do with the parametrized url (?ContentID=7) I would appreciate if anyone could help out here and would be greatly appreciative.

Thank You
Russ

g1smd


#:3876098
 9:38 pm on Mar 21, 2009 (utc 0)

You can't use Redirect or RedirectMatch for this.

Use a RewriteCond to look at QUERY_STRING, and a RewriteRule with [R=301,L] for the redirect.

Include the full canonical domain name in the target URL.

russwittmann


#:3876126
 11:02 pm on Mar 21, 2009 (utc 0)

I tried something like this but I'm lost.... because its not working either

RewriteCond %{QUERY_STRING} ^ContentID=7$
RewriteRule ^contentpage\.asp$ [domain.com...] [R=301,L]

g1smd


#:3876130
 11:17 pm on Mar 21, 2009 (utc 0)

That code allows for the
ContentID=7 parameter to be the ONLY parameter present. Is it?

I would code that as: &?ContentID=7&? or similar, so that it would still redirect if other parameters were present.

Other than that, I see no errors or issues.

Did you flush the browser cache before testing?

jdMorgan


#:3876138
 11:29 pm on Mar 21, 2009 (utc 0)

To prevent the original query string from being appended to the new URL, add a question mark to the substitution URL:

RewriteCond %{QUERY_STRING} &?ContentID=7&?
RewriteRule ^contentpage\.asp$ http://www.example.com/about/? [R=301,L]

We're presuming that you already have other working rewriterules in this file. If not, you'll need to add either the second line or both of these lines ahead of the code above:

Options +FollowSymLinks
RewriteEngine on

The first line is not required on all servers. In fact, it's not allowed on some servers. The only way to find out whether both lines are required is to test.

Jim

russwittmann


#:3876140
 11:39 pm on Mar 21, 2009 (utc 0)

ok this is working but it conflicts with my other rewrite rules here is what I have

[old rules and I need these]

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
[end old rules] ------expression engine cms uses these------

[ redirect rules ] ----works when i remove above rules -------
RewriteCond %{QUERY_STRING} &?ContentID=7&?
RewriteRule ^contentpage\.asp$ http://www.example.com/about/? [R=301,L]

russwittmann


#:3876143
 11:56 pm on Mar 21, 2009 (utc 0)

Fixed it by placing the new rules before like so, please let me know if this is correct because I will be writing about 15 of these.... thank you

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{QUERY_STRING} &?ContentID=7&?
RewriteRule ^contentpage\.asp$ http://www.example.com/about/? [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

jdMorgan


#:3876152
 12:15 am on Mar 22, 2009 (utc 0)

External redirects should always precede internal rewrites, with rules in both the redirect and rewrite groups in order from most-specific (fewest URLs affected) to least-specific.

Jim

russwittmann


#:3876172
 12:58 am on Mar 22, 2009 (utc 0)

was my fix correct? it seems to be working correctly :)

g1smd


#:3876278
 8:46 am on Mar 22, 2009 (utc 0)

It looks fine to me.

However, I would also add a couple more rules.

After the first redirect I would add a rule which fixes URL requests asking for an index file by name to redirect to URL at www with trailing slash and no index file name.

After that I would have the general non-www to www redirect that fixes all non-www requests and preserves the requested filepath when redirecting to www.

After that I would list the rewrite.

russwittmann


#:3876494
 6:53 pm on Mar 22, 2009 (utc 0)

I'm so new to mod rewrite how would I do that? I'm really interested.

g1smd


#:3876495
 6:55 pm on Mar 22, 2009 (utc 0)

Luckily. Examples for both of those are posted several times each week.

russwittmann


#:3876584
 9:32 pm on Mar 22, 2009 (utc 0)

got it but which method is better I found two below?

RewriteCond %{HTTP_HOST} ^([a-zA-Z0-9\-]*)\.com$
RewriteRule ^.*$ [%{HTTP_HOST}%{REQUEST_URI}...] [R=301,L]

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

g1smd


#:3876594
 9:52 pm on Mar 22, 2009 (utc 0)

Try this one for the non-www to www rule:

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

You also need the 'index file to slash' redirect placed directly ahead of this one. That redirect also needs to force www for those requests.

russwittmann


#:3876647
 11:35 pm on Mar 22, 2009 (utc 0)

g1smd are you talking about this rule?

RewriteRule ^(.*)$ /index.php/$1 [L]

g1smd


#:3876650
 11:40 pm on Mar 22, 2009 (utc 0)

Nope. That is your rewrite. Don't change that, but do list it last.

Ahead of the non-www to www redirect you need a separate 301 redirect that strips "index" filenames from the requested URL, and forces www for those requests.

russwittmann


#:3876693
 1:53 am on Mar 23, 2009 (utc 0)

im in a whirl wind of information overload....

people can get to my page via [domain.com...] or [domain.com...] somone said I need to force the ar of the backslash which I am trying like this

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}¦/)$
RewriteRule ^(.*)$ $1/ [L,R=301]

but this isnt working and Im going seriously bald...lol

g1smd


#:3876759
 8:43 am on Mar 23, 2009 (utc 0)

Personally, I would remove the slash, as a slash is supposed to represent a folder.

You do that with a redirect, but again, a redirect must contain the full domain name in the target URL otherwise that redirect creates a non-www and www duplicate URL, which then gets corrected by a later redirect creating a redirection chain. Fix the www part within the same redirect for these requests.

There's plenty of prior example code for removing the slash.

 

Home / Forums Index / The Webmaster World / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
WebmasterWorld ® and PubCon ® are a Registered Trademarks of WebmasterWorld Inc.
© WebmasterWorld Inc. 1996-2010 all rights reserved