Forum Moderators: phranque

Message Too Old, No Replies

Need .htaccess Code, Thanks

Two lines of code needed to fix 10,000+ links

         

magnets

9:05 pm on Feb 27, 2011 (gmt 0)

10+ Year Member



Yesterday I created tens of thousands of invalid URLs. The website now needs to be totally re-indexed by Google. But until that happens I really need to get my rewrite code correct. Sadly, it does not currently work. Any help would be appreciated.

Instead of giving you my apparently error filled two lines of code I will just tell you the situation and I will use your clean code. Thanks!

I had:

http://www.example.com/example/directory/whatever.php

I now have:

http://www.example.com/directory/whatever.php

So I guess I need a condition statement and a rewrite statement but whatever I have tried does not work. At least the two statements I put in the .htaccess file now do not take down the entire website like they did the first time I made an attempt. But, they do not work. (:(

g1smd

10:04 pm on Feb 27, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Not enough information, and yes we do need to see your code.

It might be a very simple typo, easily fixed.

There are several steps needed here:
- a rewrite to connect external incoming URL requests to the server internal path where the content actually resides,
- a redirect such that if someone directly requests the content path, they are redirected to the correct URL,
- a redirect such that if someone requests one of your new "wrong" URLs they are redirected to the correct new URL.

You need to be very clear about URLs "used out on the web" and server filepaths "used inside the server". They are two different things, and getting the terminology wrong can be fatal.

magnets

11:31 pm on Feb 27, 2011 (gmt 0)

10+ Year Member



Sorry, I will have to make up something new. I deleted the code that was obviously wrong.

Is there an example somewhere of an URL that comes in like:

http://www.example.com/example/directory/whatever.php

and it gets instead sent to:

http://www.example.com/directory/whatever.php

I will use that example and create the code and let you know if it works. Or has no one ever had to do that before?

Thanks.

g1smd

11:39 pm on Feb 27, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



gets instead sent to

This is vague language and could have two meanings

You might mean:

User requests
www.example.com/example/directory/whatever.php
and server rewrites request to internal path at
/directory/whatever.php


or you might mean:

User requests
www.example.com/example/directory/whatever.php
and server sends redirect suggesting browser makes a new request for the new URL:
www.example.com/directory/whatever.php


The rewrite is a URL to filepath translation.

The redirect is a URL to URL suggestion.

Understanding the difference is crucial.

Parallel conversation: [webmasterworld.com...]

magnets

3:19 am on Feb 28, 2011 (gmt 0)

10+ Year Member



Hopefully this helps.

I never ever want to see the URLs of the form
www.example.com/example/directory/whatever.php
indexed by search-engines. Currently there are 10s of thousands. I want them to go away as soon as possible. Until then I want them to go to URLs of the form
www.example.com/directory/whatever.php
The latter are the only valid form of the URL. The "/example/" should never again be seen in the search-engine databases as soon as possible.

g1smd

3:29 am on Feb 28, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Here is the code for the redirect:

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


Additional code (a RewriteCond) will be required ahead of that redirect if requests for valid URLs are subsequently rewritten in order to fetch the content.

magnets

5:03 am on Feb 28, 2011 (gmt 0)

10+ Year Member



Thanks for the RewriteRule. It definitely looks like it should work. I'll have to play around to see what else is wrong.

You are by far the most generous and knowledgeable person in this area. You should get a raise from all your fans.

g1smd

7:51 pm on Feb 28, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Posting at 3.29 a.m. local time is never a good thing.

There was a typo in the code. The redirect creates a double slash.

The very subtle correction is:

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

OR
RewriteRule ^example/(.*)$ http://www.example.com/$1 [R=301,L]


Report any issues or ask more questions. No problem.