Jump to content

domain/folder/file redirect htaccess


jokerfool

Recommended Posts

If I have a link that keeps appearing in search engines thats wrong and goes no where, can I use the redirect in the htaccess file to specify wildcards e.g.

 

http://www.domain.com/abc/blah/123.html

 

to redirect any link within /abc/ to go back to domain.com?

 

I know I can set up

 

Redirect 301 http://www.domain.com/abc/123/asdf.html http://www.domain.com

 

But can I do

 

Redirect 301 http://www.domain.com/abc/* http://www.domain.com

 

Thank you.

Link to comment
Share on other sites

The value you give Redirect is just a prefix, so if you wanted to redirect everything under http://www.domain.com/abc/ you can just do 

Redirect 301 /abc/ http://www.domain.com

 

Note however that if someone requested http://www.domain.com/abc/123/asdf.html, it will keep the part after the prefix and append it to the new url, so the redirect would attempt to send them to http://www.domain.com/123/asdf.html.  To strip the value, you'll need to use mod_rewrite and a rewrite rule.

 

That said, if that content does not exist anymore, a redirect like that is not what you want to send.  You want to send a 410 (Gone) status so that the search engines will stop trying to access that URL and remove it.  Sending a 410 makes it so you can't send a new location for the redirect also, but you could configure an ErrorDocument for 410 that will do a redirect using a meta refresh.

 

ErrorDocument 410 /errors/410.html
Redirect 410 /abc/

 

Then in /errors/410.html

<html>
 <head>
  <title>410 Gone</title>
  <meta http-equiv="Refresh" content="5;url=http://www.example.com/">
 </head>
 <body>
  <p>The document you requested has been removed.  Please <a href="http://www.example.com/">return to the home page</a></p>
 </body>
</html>

Edited by kicken
Link to comment
Share on other sites

In Google there are hundreds of *.html files that are indexed, is there an easy way for me to redirect those links to those html files whatever they may be to the main domain?

 

Redirect 301 /abc/ http://www.domain.com
Cant I use wildcards or something?
Redirect 301 /abc/* http://www.domain.com

 

Thank you.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.