A permanent 301 redirect in your .htaccess file lets search engines and others know that a old link has been replaced by a new one. It's the recommended method for directing traffic from an existing page.

Some common uses of a 301 .htaccess redirect:

You have the ability to setup redirects for a domain in your cPanel interface one at a time, or following the steps below you can modify your .htaccess file directly to add these manually yourself.

Getting to your .htaccess file

On a Linux server you would use your .htaccess file to implement a 301 redirect for your pages.

  1. Login to your cPanel.
  2. Under Files, click on File Manager.
  3. Select the Document Root for: option, and choose your domain from the drop-down.
  4. Ensure that Show Hidden Files is selected.
  5. Then click Go.
  6. file-manager-hidden-files
     
  7. Right-click on the .htaccess file and select Edit.
  8. file-manager-htaccess-edit
     
  9. If your .htaccess file didn't exist already during the previous step, click on New File at the top-left, name the file .htaccess, and finally set the directory for the file to be created to /public_html/ or the document root of your site.
  10. file-manager-htaccess-create
     
  11. You might have a text editor encoding dialog box pop-up, you can simply click on Edit.
 

Redirect individual files

To redirect individual files, like example.com/oldfile.htm to newfile.htm you can use a 301 redirect like this:

Redirect 301 /oldfile.htm /newfile.htm

single file 301 redirect

To redirect one specific file to another domain such as example.com/oldfile.htm to example.net/newfile.htm:

Redirect 301 /oldfile.htm http://example.net/newfile.htm

single file domain 301 redirect

Redirect an old domain to a new domain

If you had an old domain such as example.com, and now you decided you actually want to use example.net for the website. You could setup a 301 redirect for the entire domain, so that old links to example.com carry over.

Code in the example.com domain's .htaccess file:

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

full domain 301 redirect

Force www. version of domain to be used

A search engine like Google would see example.com and www.example.com as essentially two separate websites. They recommend you pick one version you'd like search engines to display and using a 301 redirect is a possible option.

If you have a lot of links on the web where people are linking to your site as example.com, but you would like your visitors to instead end up at www.example.com you can force this version of your domain with these rules:

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

force www 301 redirect

Force non www. version of domain to be used

If you have a lot of links on the web where people are linking to your site as www.example.com, but you would like your visitors to instead end up at example.com you can force this version of your domain with these rules:

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

force non www 301 redirect

Redirect all files with certain extension

To re-direct all of one type of file to another, such as example.com/file.php to example.com/file.htm

RewriteEngine On
RewriteCond %{REQUEST_URI} .php$
RewriteRule ^(.*).php$ /$1.htm [R=301,L]

file extension 301 redirect

You should now know how to properly setup 301 permanent redirects on your website to help ensure that search engines and visitors coming to your site from older links can still get to your new content.

Did you find this article helpful?

We value your feedback!

Why was this article not helpful? (Check all that apply)
The article is too difficult or too technical to follow.
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
How did you find this article?
Please tell us how we can improve this article:
Email Address
Name

new! - Enter your name and email address above and we will post your feedback in the comments on this page!

Like this Article?

Related Questions

Here are a few questions related to this article that our customers have asked:
Ooops! It looks like there are no questions about this page.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question
n/a Points
2014-05-03 11:01 am

Need a solution to this, not addressed above.  Want to redirect all "example.com/shop" to "www.example.com/shop" pages.  Our SSL certificate covers "www" pages on our shopping cart (i.e. "www.example.com" not "example.com").  On occasion, customers will try to go to a cart page without the "www" prefix and get a warning notice because certificate doesn't cover those pages.  Cart settings usually force the "www" but occasionally fail and/or need to be reset.  

Have tried to create a redirect, but keep getting "loop" errors.  Above discussion doesn't address this specifically.  Any help would be appreciated.

Staff
8,322 Points
2014-05-05 8:57 am
Hello Raplh,

Thank you for your question. We have a general guide on How to force www or non-www in htaccess.

What program are you using to build your website? Depending on your CMS, you may a have to accomplish this a different way. For example, in Wordpress, you would change the site URL from http://example.com to https://www.example.com.

If you have any further questions, feel free to post them below.
Thank you,

-John-Paul
n/a Points
2014-06-08 12:48 pm

Please provide me solution

 

I want to redirect my site from

http://bluemoonacres.net/in-our-markets/

to

http://bluemoonacres.com/in-our-markets/

For all my websites link

 

Please Please Please

Iam stucked

Staff
17,456 Points
2014-06-09 12:16 pm
Hello Pardeep,

If you are simply wanting to redirect the .net to the .com, you will want to follow the instructions for redirecting from old domain to a new domain. You can simply add the /in-our-markets/ to the end of the domain names to assist with the redirects.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com/subfolder [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com/subfolder [NC]
RewriteRule ^(.*)$ http://example.net/subfolder/$1 [L,R=301,NC]


Kindest Regards,
Scott M
n/a Points
2014-06-13 8:19 am

Thanks, it helped me a lot.... I wanted to redirect all old links from asp pages to php pages, and the article "Redirect all files with certain extension" almost worked, except that it would redirect to the root site for links within subfolders...

for eg: i would like to redirect http://examplesite.ext/sub/page1.asp to http://example.ext/sub/page1.php

But the code shown here redirects to http://example.ext/page1.php

please help

Staff
8,172 Points
2014-06-13 9:15 am
The following code will allow you to redirect but keep the folder structure:

RedirectMatch 301 (.*)\.asp$ http://www.example.com$1.php

n/a Points
2014-06-18 10:51 pm

I want to move my site from a nation domain to .com domain, could you suggest me to do it. 

it's is www.lacda.vn and move to www.muhato.com

Staff
8,172 Points
2014-06-19 8:22 am
You would simply need to buy the new domain if you have not already, and add it to your cPanel as an addon domain or perform a primary domain change on your account. Depending on how your site is built, you may also need to make some additional configuration changes if anything is referencing the old domain directly.
n/a Points
2014-06-30 3:06 pm

Good afternoon,

I have create some subdomains for my basic domain. Because I have an SSL card only for principal store, I want that the all login page, registered page and sign-up page and check-out page from all sub-domains to be redirect on basic store. Some example of links are:

- https://mysite.com/login.html (login page from basic store)

- http://sub-domain-1.mysite.com/login.html  (login for sub-domain 1, corresponding to login page)

- http://sub-domain-1.mysite.com/?route=account/signup (signup for sub-domain 1, corresponding to signup page)

- http://sub-domain-1.mysite.com/create-account.html (register for sub-domain 1, corresponding to register page)

- https://mysite.com/checkout.html (check-out page from basic store);

 

Also, I observe that on my home page from basic store don´t appear https on browsers. How I can allow to appear https on home page, also using .httaccess file?

Thank you very much for your advice and support.

I waiting your advice.

Best regards.

P.S. I use OpenCart 1.5.6, multi-store (under the same admin, multiple stores)

Staff
16,247 Points
2014-06-30 4:19 pm
Hello Johnny P,

SSL certificates are made to work with a specific URL. So, if you order it to go to "https://mysite.com", then all sites in that URL should be secure. However, since you're using a different URL than what was specified for the SSL, the certificate does not protect it. The URL that you mentioned above (sub-domain-1.mysite.com/login.html ) will not work because it is not formatted for the SSL that was purchased. However, there is a way to use the subdomains in this way as long as they are using the primary domain.

If you were to use a Wildcard SSL (you would have to specify that during the purchase of the SSL), then you could use the subdomain format that you're using:

subdomain.mysite.com

However, if you're using 2 different URLs (you mentioned a principal store and a basic store), the SSL will not work that way. You would definitely need to purchase 2 different SSL certificates.

I hope that helps to clarify the answer. Please let us know if you require any further assistance.

Regards,
Arnel C.

n/a Points
2014-06-30 11:54 pm

Good morning,

Thank you for answer Arn.

I know this basic detail reffering to SSL Wildcard. Fortunately, OpenCart share the same details for all their sub-domains. This Is the reason because only I want to redirect some basic links (such I specified anterior). When somebody want to login on my some sub-domains, than automatic will be redirected on the corresponding page from basic store (is the same think as principal store, but in other words).

I can redirect those link using file 301 and htaccess? What is the command line which I can add it to ensure redirection? Also I don´t have in my ftp the 301 file.

Thank you for support and advice to all comunity.

I waiting your answer.

Best regards.

Staff
17,456 Points
2014-07-01 9:10 am
Hello JohnnyP,

If I am correct, you are asking if it is possible to redirect http://login.example.com to https://example.com/login. This can absolutely be done via the htaccess file, but it can be done even easier via the redirect tool for cPanel. This writes the .htaccess code for you. I have tested this on my own server and it worked perfectly.

Kindest Regards,
Scott M
n/a Points
2014-07-01 12:54 pm

Hello

I moved my site from ASP to WordPress an I need to redirect any .asp page to the site root. I tried with this code but it doesn't work

RewriteEngine On
RewriteCond %{REQUEST_URI} .asp$
RewriteRule ^(.*).asp$ /$ [R=301,L]

$nbsp;

Any help will be welcomed

Redards

Staff
9,965 Points
2014-07-01 2:58 pm
Hello Ciro,

You would more than likely want to insert your rewrite rule inside the default WordPress .htaccess rules like this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.asp$ /index.php [R=301,L]
RewriteRule . /index.php [L]
</IfModule>
# END WordPress


Please let us know if that is working for you.

- Jacob
n/a Points
2014-07-02 4:32 pm

Thanks Jacob!

Staff
9,965 Points
2014-07-02 6:03 pm
Hello Ciro,

No problem at all, glad to help out!

Taking a closer look at this, it looks like I might have given those rules to you in haste. While it does seem to technically force all requests for a .asp page to your main WordPress page, it looks like it also possibly breaks the inclusion of CSS files and images.

So you would want to use the redirect code above your default WordPress rules like this instead:

RewriteEngine On
RewriteRule ^(.*)\.asp$ / [R=301,L]

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress


Also as I've answered Heidy's question below about the SEO impact of directing old URLs to new ones. You might also want to think about directly setting up a 301 redirect if you've got the same content just in WordPress now.

Redirect 301 /helpful-page.asp /helpful-page


Please let us know if this works out for you!

- Jacob
n/a Points
2014-07-02 1:46 pm

Hello,

I appreciate very much your help to solve the following issue.  

There is already a live site created long ago in Dreamweaver with .htm and .html files. Recently, I created a completely new site with Joomla 2.5 in a subdirectory under the same root directory of the old site.  My intention now is:

1) Redirect all trafic to the subdirectory where I have the new joomla site, using the same domain.

2) I will keep the old site as it is, but I need to redirect old .html and .htm pages to the new corresponding pages in joomla 2.5 to avoid loosing ranking position in search engines.

3) I am concern that redirecting old pages to new pages would be a bad practice for search engines like Google.  I want to make sure that this will not be a problem, and if it is, then what it is the correct way for doing it.

I appreciate your help and explain how to do the above.

Thank you very much.

Staff
9,965 Points
2014-07-02 3:58 pm

Hello Heidy,

Luckily you can redirect your old .htm and .html pages to your new Joomla site, and won't lose any search engine ranking in the process when done correctly.

Search engines use the 301 redirect from a server to update their indexes to make sure they link to your fresh content. Search engines love it when you let them know a old helpful page can now be found at a new home. It helps their users get the most relevant and up to date content, and lets the search engine know you have someone maintaining your site and updating things.

Here is a great page from Google on 301 redirects and why you want to make sure to use it when updating your content. Hopefully that will help put you a little bit at rest for worrying about search engines not liking you updating your links.

Now do keep in mind from a SEO or Search Engine Optimization stand-point, if you're getting a lot of traffic to your HTML page about "how to use a PC". Then you go and completely change the content that was in your HTML page on the Joomla version, for instance you update it with tips on "how to use a Mac" and removed some of the PC information you had before. Over time you could lose ranking for the "how to use a PC" keyword phrase, because search engines care about relevant content and the reason people used to click on your page from Google results might not be there anymore.

To redirect all of your old HTML pages to your new Joomla subdirectory, you would simply edit your .htaccess file and use one of the following formats:

Redirect 301 /helpful-page.htm /joomla/helpful-page


Or include the full URL:

Redirect 301 /helpful-page.htm http://example.com/joomla/helpful-page


I hope that helps, and if you have any further questions at all, please let us know!

- Jacob
n/a Points
2014-07-02 4:10 pm

Perfect!  Thank you very much for your prompt response.  

Staff
9,965 Points
2014-07-02 4:29 pm
No problem Heidy, thanks for stopping by and commenting on my guide :)
n/a Points
2014-07-07 10:35 am

Hi!

How can i redirect joomla subdirectory to article ? Like mypage.com/subdir -> mypage.com/index.php/article=1

Staff
17,456 Points
2014-07-07 10:49 am
Hello Punkel,

The best way to do that would be to use the cPanel redirect tool. It will write the code for you and place it into your .htaccess file.

Kindest Regards,
Scott M
n/a Points
2014-07-07 3:36 pm

Thank you, but my site does not have cPanel. Can you paste here .htaccess example?

Staff
9,965 Points
2014-07-07 3:50 pm
Hello Punkel,

You would simply add this towards the top of your .htaccess file:

Redirect 301 /subdir /index.php/article=1



However further down the file, you'll need something that handles the rewrite of that /index.php/article=1 to actually do something. As article=1 is not a valid URL when just used like that as it would essentially be the same as requesting /folder-name=1 and most of the time you aren't going to have a folder or file with a = symbol in it.

Typically you're going the reverse where you want to go from a URL like /index.php?article=1 and make it a search engine friendly URL like just /page-name.

- Jacob
n/a Points
2014-07-08 1:59 am

Thank you a lot, this Redirect 301 /subdir /index.php/article=1

works perfectly. I use this redirect only for search bots.

Staff
9,965 Points
2014-07-08 2:10 am
Hello Punkel,

Awesome, glad that helped! It's still a little odd to see a search friendly URL being converted back to a numbering system. So if you happen to be trying to block bad bots for some reason with this redirect, you would find my guide on block users with .htaccess helpful, or even how to identify bad bots.

I hope you're not having a malicious bot issue, and just need to redirect to that URL format for some other reason instead. If so, again I'm glad it helped!

- Jacob
n/a Points
2014-07-08 1:26 am

Hello,

Good Morning

My Site is single page site that's and my Domain is http://example.com/#!/ and i have to convert this domain to http://example.com using 301 redirect then which code i have to use?

Staff
9,965 Points
2014-07-08 3:00 am
Hello Rinku,

You wouldn't be able to use a 301 redirect, or to my knowledge any RewriteRule rule to be able to alter the URL like that.

The pound symbol # doesn't actually go to the server for processing, it is all handled by the front-end. You can confirm that if you have access to your website's access logs and look at the request. So either the browser interprets it as an anchor link and navigates the user to a specific spot on the page. Or JavaScript grabs it and interacts with the browser's DOM in some fashion.

If you hit Ctrl-U in your web-browser you can see the HTML of your page, and you should notice this on the 4th line:

!-- Mirrored from example.com/index.html by HTTrack Website Copier/3.x



So it looks like this one page website might have been copied from another server, and in doing so, looks like it retained a bunch of links including #! already for switching to multiple pages of info when a link is clicked.

It looks like your /js/switcher.js file is responsible for this:

defHash:'#!/',
emptyHash:'#',



So it looks like this switcher JavaScript file is causing the #! part of the URL to show up in the browser more than likely. But the web page is using it for navigation, so if you simply tried to remove it, it would also remove the functionality of your links pulling up the different pages of the one HTML page.

Hope that helps, please let us know if you had any further questions.

- Jacob
n/a Points
2014-07-16 4:20 am

My website opening with "www" and without "www"  -- I want my website always open without "www" if some one open with "www" it should be redirect in without "www" - please inform me - how can i solve this problem - website made in PHP . thanks

 

Staff
9,965 Points
2014-07-21 7:21 pm
Hello Shashi,

You can use the .htaccess rules mentioned above from the force non www example in this guide:

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



This will force all requests for www.example.com to instead just redirect to example.com without the preceding www at the beginning of the domain.

Please let us know if you needed anything else at all.

- Jacob
n/a Points
2014-07-28 5:05 pm
stop creating cartoons and create a text-only step-by-step version
Staff
9,965 Points
2014-08-01 3:29 pm
Hello Stu, and thank you for your suggestion.

There are already many text-only versions out there that cover 301 redirects on the Internet, was there a specific way of redirecting you were unable to figure out by following the current text with animations on this guide?

In my experience I've found that most people when they are writing rewrite code want to know what the end result is going to do in their web-browser. I thought there would be no better way to show that then literally showing what happens when you activate a particular rewrite rule and then watch it in the browser to see what it does.

- Jacob
n/a Points
2014-07-28 8:30 pm
Give more explanations
Staff
9,965 Points
2014-08-01 3:34 pm
Hello shregs, and thanks for your comment,

Was there any particular examples you were looking for, or what in your opinion could use more explanation to be easier to understand?

- Jacob
n/a Points
2014-08-01 3:21 pm

I have a website that I am working on that had multiple domain names because we have multiple companies. They were all leading to the same website, but with different URL addresses. I didn't want a duplicate content issue, so I redirected all of the multiple domain names to the main website name since we rebranded about 6 years ago and the last webmaster didn't do any 301 redirects from the old domain to the new one. I am also trying to get the link juice from those domains and recover the history of the last domain because we still own it and it's 15 years old as opposed to the current domain that is 6 years old. Will Google penalize me for doing this or is this the positive step for my SEO? Also, do you know how long it will take to get the history of old domain to merge with our newer domain? Any help is apprecaited

Staff
9,965 Points
2014-08-01 3:58 pm
Hello Joy,

It would really depend on the niche that your website is in, but for the most part having multiple domain names pointing to the same website content is not going to help you SEO wise. In some cases it can hurt you by getting penalized for duplicate content as described by Google.

It would help to get a better understanding of exactly what you're trying to do before we could offer an real recommendation as to what you might want to do. I'd recommend checking out the Google Webmasters page about change page URLs with 301 redirects it also has a good video on it from Matt Cutts at Google talking about when you might want to use a 301 redirect.

In order to get link juice from an old domain, if you had a page like example.com/how-to-tie-a-tie that was ranking well for the search query how to tie a tie, then you'd want to make sure that you're passing on that ranking to your new domain with a 301 redirect. So you would have it go to a matching URL on your new domain such as example.net/how-to-tie-a-tie that also contains related info to what the old domain had been ranking for.

In regards to your questions about older and newer domains, those don't really hold as much weight as they use to in the SEO world. It's really more about the content of your website as opposed to the domain they are hosted on. If you're currently ranking high for something on a newer domain, setting up a 301 redirect for it to now be on an older domain isn't going to really give you much of a boost if any at all.

If you can be more specific in your question with examples of exactly what you're attempting to do we can attempt to provide you a better answer for your specific situation.

- Jacob
n/a Points
2014-08-01 4:18 pm

Thanks Jacob,

I already read everything that I could find about it. I am not talking about recovering pages since our old website is long gone as are the pages and I don't know the page names or extentions to redirect anyway.

When we changed our company name, they changed the domain name of the website without doing a 301 redirect. They did however, set up the server host to redirect customers from the many domain names to the current one. They also already had the multiple domain names that went to the same site, but with a different URL.

The reason that I am trying to do a 301 redirect is because I don't want a duplicate content issue. I want Google to see it as all one website and one domain that was permanently moved. 

I also want to obtain the link juice since they are our domains and they do point to the same site. Does that make sense? The domain names are all our company names and they are not the same, but they are all owned by us and go to that site anyway.

Staff
9,965 Points
2014-08-01 4:49 pm
Hello Joy,

You could probably look at your old site's access logs and see what URLs are still being directly accessed, and then 301 redirect those over to relevant pages on your new site.

If you just wanted to 301 redirect all your old sites to the main landing page of your new site, that should be fine, but you're not going to really get any SEO benefits out of that. As essentially you're telling search engines, this old piece of content that my old site is ranking for about how to tie a tie is now on this new website, but then when the bot gets to the new website there is no information about that search term. So over time if you were ranking for that topic and people are seeing that content no longer exists you'll drop in the search engine rankings for that term.

We would really need a direct example of what it is your're trying to accomplish with your sites to give you a good recommendation. I don't quite understand what it is you're trying to accomplish just by your explanation but if you could give us some real world examples I'm sure we could help you out.

- Jacob
n/a Points
2014-08-01 5:25 pm

As an example: (These are not the real website URL's and if they are, then they weren't used by for the purpose of example only)

We had a company www.movingcompany.com and they were affiliated with a larger company www.vanlines.com, but not owned by that company, but rather an "agent" of that company.

Then www.vanlines.com got purchased and merged with www.biggervanlines.com and we respresented both sides (2 companies) and had two company names www.movingcompany.com (agent of www.vanlines.com) and www.othermovingcompany.com (agent of www.biggervanlines.com)

We also had other devisions of our company like www.recordstorage.com, etc... I don't know who's great idea this was, but this is what I'm working with here lol. And there are about 4 of these.

Then 6 years ago we decided that it was too much and changed our domain to www.movingcompanies.com to represt all of it under one name. I wasn't a part of any of that decision making. I'm just trying to optimize and recover what may have been lost 6 years ago because proper 301 redirects weren't done.

When we changed our domain name, they didn't do any 301 redirects from the old sites to the new site in the .htaccess file. They only redirected through the server host. So the domains are there, but they all have different URLs that take them to the same landing page www.movingcompanies.com (the new site)

Each domain has internal and external site links pointing to and from the domain. What I am trying to do is get www.movingcompanies.com to be reconized by Google as the same domain so that the past links from the old websites are credited to the new website. I just wanted to confirm that 301 redirects were the best possible way to do this or if I should even bother at this point.

Staff
9,965 Points
2014-08-01 5:40 pm
Hello Joy, thanks for the examples.

Going the 301 redirect route would be how you'd want to transition all of the old domain names to your main new one, and to also let Google and other search engines know about the transition.

However because you're talking about sites that are 6 years old and I'm assuming have different content on the new site, you're not going to really see a SEO benefit for keywords driving traffic to your sites.

For instance in your example if your vanlines.com site is currently ranking on the first page of Google for van moving, and your biggervanlines.com site is ranking for big van moving. If you 301 redirect all requests for these 2 domains to the same front landing page on your movingcompanies.com domain, but you don't have the same content for van moving on that page that allowed your old site to rank well, just setting up a 301 isn't going to make the new site rank any better for that term.

Basically if past links from your old sites aren't relevant to the new site, setting up a 301 redirect will allow people to get to the new site but if the content isn't the same as when it was on the old site it's not going to bring SEO benefits to your new site.

- Jacob
n/a Points
2014-08-01 6:02 pm

Thank you. The content is basically the same. It's a new/old webpage, but they are all moving companies and moving related and because this happened 6 years ago, these domains aren't ranking in Google as webpages. They are only old and there. I'm hoping that the link value will merge because they all essentially link to where the user would want to go. Which is to the moving company that just happened to change domain names awhile back. I appreciate all of your input and help.

n/a Points
2014-08-04 7:11 am

hey Jacob, I am using the followingrewrite rules:

RewriteEngine on

RewriteRule ^courses/chemistry/5-13-organic-chemistry-ii-fall-2003/(.*)$ http://hdl.handle.net/123456789/286 [L,R=301]

RewriteRule ^courses/chemistry/5-12-organic-chemistry-i-spring-2003/(.*)$ http://hdl.handle.net/1721.1/86886 [L,R=301]

but i need to do the deep linking and get the result like :

http://dspace.mit.edu/bitstream/handle/1721.1/86886/20-320-spring-2006/contents/index.htm

how can i fetch the 20-320-spring-2006(shortname for URL) and index.htm after the slash(/) dynamically.

Please suggest a way and help me out. Kindly give us a code as a example using my data.

What is the best practice to write a rule in .htaccess file, whether we should write all the redirects in on .htaccess file or we can write it in different .htaccess files for different folders.?

 

Staff
17,456 Points
2014-08-04 11:17 am
Hello Abhishek,

I am not quite following your request. Are you saying you want to redirect: http://dspace.mit.edu/bitstream/handle/1721.1/86886/* (meaning anything under the 86886 dierectory) to a specific place?

Kindest Regards,
Scott M
n/a Points
2014-08-08 4:07 am

Hi,

Can you help on my issue? My website's same content is available via 2 URLs: like http://domainname.com/ and http://XXX.XXX.XXX. XXX opens same content. Similarly it is happening for all internal pages also: http://XXX.XXX.XXX.XXX/internal-content-url/ and http://domainname.com/internal-content-url/ opens same content and google thinks it is duplicate content and drops my site ranks.

I am using dedicated IP on a dedicated server and WordPress CMS

I tried to write redirection URL in .htaccess file but it worked for homepage only not internal pages.

Any advice will be deeply appreciated.

Staff
17,456 Points
2014-08-08 9:26 am
Hello Anshit,

You can 301 the IP address to the domain name. You may want to try the following code as a template. (Assume an IP address of 123.45.67.89 and a domain name of example.com)

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

Kindest Regards,
Scott M
n/a Points
2014-08-08 3:29 pm

Thanks for your reply Scott,

I am using the same code in .htaccess file but it is redirecting only the home page. Not the internal pages. 

Staff
8,322 Points
2014-08-08 4:19 pm
Hello Anshit Gupta,

Check to make sure there are not other .htaccess files within your subfolders. This would cause them to override the rules you are creating in the folder above.

Also ensure there are not other rules within your .htaccess, interfering with this redirect. For example, CMS's typically include a list of rules, and can add more rules from plugins/addons.

If you have any further questions, feel free to post them below.
Thank you,

-John-Paul
n/a Points
2014-08-09 3:19 am

Checked it couldn't find any other htaccess file in subdirectories.

Homepage redirects fine but internal pages are still accesible via IP. Don't know whats the reason.

Is there any other alternative besides working on .htacess?

Staff
17,456 Points
2014-08-11 11:10 am
Hello Anshit,

Give this next piece of code a try. The first, to my knowledge, should have worked as well.
Options +FollowSymLinks
RewriteEngine on
#
# Redirect all requests for all non-canonical domains to same page in www.example.com
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]


Kindest Regards,
Scott M
n/a Points
2014-08-14 12:21 pm

Hi eveyone I am having some trouble becaue someone installed a wordpress site in a subdirectory under cpanel because there is a static page create for home so you can see in www.domain.com a page that says enter site and redirects to www.domain.com/wordpress and in .htaccess you can see this code:

Options +FollowSymlinks

DirectoryIndex index.htm index.php

RewriteEngine on

RewriteCond %{HTTP_HOST} !^www\.domain\.com$

RewriteRule ^(.*)$ http://www.domain\.com/$1 [R=permanent,L] 

RewriteCond %{REQUEST_URI} !^/$ 

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

Ok, the things is that I have added an addon domain because I want to have a new site, the domain is www.domain2.info, it is added correctly but when you try to go to www.domain2.info it redirects to www.domain.com/domain2.info/

Thanks in advance for any help.

Staff
16,247 Points
2014-08-14 12:37 pm
Hello Jorge,

Sorry for the problem that you're having with the domain. This is typically the result of a domain being used as an add-on domain that has either NOT been registered with a domain registrar, or the domain is still undergoing what is called domain propagation.

If you have not registered the domain name, then you can use the Account Management Panel (AMP) to register the domain.

I hope this helps!

Regards,
Arnel C.
n/a Points
2014-08-14 12:48 pm

Actually the domain is registered and propagated because if you enter it resolves, the problem is that it redirects to the main domain of the account that is why I pasted the .htaccess code of the main domain. The domain is no registered with inmotion but the hosting account is under my inmotionhosting reseller account and the plan has enable addon domains.

Staff
16,247 Points
2014-08-14 1:12 pm
Hello Jorge,

The reason I mentioned that issue could be a non-registered domain, or a domain undergoing propagation is because we do not know you domain name and it's a common cause to the issue.

The .htaccess file applies to ALL of the folders beneath it unless you provide another .htaccess file. So, if your add-on domain is being affected by the .htaccess file in the primary domain, you need to put an .htaccess file at the root of the add-on domain. This prevents it from following the rules you set in the primary domain's .htaccess file.

Please let us know if you require any further assistance.

Regards,
Arnel C.
n/a Points
2014-08-18 4:58 pm

Hi,

My new site uses url names with php queries like

home.php?id=home

and I need to do a 301 redirect from home.php to home.php?id=home

I have tried

redirect 301 /home.php http://www.mysite.com/home.php?id=home

but this does not work

Can you help with the correct code?

Many thanks

Alan

Staff
16,247 Points
2014-08-18 5:37 pm
Hello Alan,

The problem may have to do with your web server. Try using a re-direct as per the directions above:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/home.php?id=$1 [L,R=301,NC]

If you continue to have problems with the re-direct, make sure to look at the variations above and try these options for your re-direct. Otherwise, please provide us more information on your website, such as the URL, so that we can investigate it further.

Kindest regards,
Arnel C.
n/a Points
2014-08-19 6:46 am

I am currently using a permalink structure with .html extension at the end.

I now want to modify to a permalink without .html extension like

http://www.abcd.com/how-old-are-you

Can you please me with the correct redirection code?

Anand

Staff
17,456 Points
2014-08-19 8:12 am
Hello Anand,

In order to remove extensions in the address bar, you will want to take a look at our article on doing just that.

Kindest Regards,
Scott M
n/a Points
2014-08-21 12:15 pm

Hello,

I'm not a customer of inmotion, but still hoping for a little insight on the following:  If you are moving a blog that currently lives on a  blog.website.com subdomain to a new format/design located at www.website.com/blog AND (this is the interesting part) the blog. subdomain is hosted by a separate company from the one which hosts www.website.com, how does one go about implementing the redirects?

My understanding is that you have to "own" the site you're redirecting pages from, as well as the one you're redirecting pages to.  So, do you need to have ownership of the blog subdomain transfered from one host to the other? And then have that company upload the .htaccess file for all individual blog post redirects?

Thanks for any help,

Nicholas

Staff
17,456 Points
2014-08-21 1:14 pm
Hello,

You do not need to own the destination of a redirect. For example, I can redirect my domain to google.com, or even your blog if I wish. If you do not own the destination site, however, you have no control over how things work on it. That is the caveat. Your .htaccess file can redirect to another server, however any changes on the other server would need to be made on that server by someone with access to it.

I hope that helps a bit.

Kindest Regards,
Scott M
n/a Points
2014-08-22 2:02 pm

Super helpful, and thanks very much for the response!

-nicholas

 

n/a Points
2014-08-21 1:17 pm

Ok, so i messed up. I was wanting to run a redirect on my 1&1 website. and I had seen a lot of people telling me to alter the .htaccess file in order to do so. I have altered the code to send any mobile browser to an alternate page. The major problem is that the redirect page im using is on the same domain, so I keep getting reloaded on a mobile device. I need to reverse this code and I dont know how. I ran this as a script through my <head> section and when I removed it, it stayed in place because ive altered the server. 

Enough of what i think i know:

 

how do you reverse this:

RewriteEngine On

RewriteBase /

 

RewriteCond %{HTTP_USER_AGENT} (android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge\ |maemo|midp|mmp|mobile.+firefox|netfront|opera\ m(ob|in)i|palm(\ os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows\ ce|xda|xiino [NC,OR]

RewriteCond %{HTTP_USER_AGENT} ^(1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a\ wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r\ |s\ )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1\ u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp(\ i|ip)|hs\-c|ht(c(\-|\ |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac(\ |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt(\ |\/)|klon|kpt\ |kwc\-|kyo(c|k)|le(no|xi)|lg(\ g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-|\ |o|v)|zz)|mt(50|p1|v\ )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v\ )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-|\ )|webc|whit|wi(g\ |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-) [NC]

RewriteRule ^$ http://www.collinscustomjewelers.com/mobile [R,L]

Staff
17,456 Points
2014-08-21 2:16 pm
Hello Flapjack117,

If that is the code that is on that domain causing the loop, it appears it needs another rewrite condition that says if it is coming from www.collinscustomjewelers.com/mobile don't try again.

It will look something like:
RewriteCond %{REQUEST_URI} !^/mobile


You can place that right before the rewrite rule so it appears as below:
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_USER_AGENT} (android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge\ |maemo|midp|mmp|mobile.+firefox|netfront|opera\ m(ob|in)i|palm(\ os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows\ ce|xda|xiino [NC,OR]

RewriteCond %{HTTP_USER_AGENT} ^(1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a\ wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r\ |s\ )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1\ u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp(\ i|ip)|hs\-c|ht(c(\-|\ |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac(\ |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt(\ |\/)|klon|kpt\ |kwc\-|kyo(c|k)|le(no|xi)|lg(\ g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-|\ |o|v)|zz)|mt(50|p1|v\ )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v\ )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-|\ )|webc|whit|wi(g\ |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-) [NC]

RewriteCond %{REQUEST_URI} !^/mobile

RewriteRule ^$ http://www.collinscustomjewelers.com/mobile [R,L]


I tested this with my own domain and it worked successfully. Hopefully it will do so for you as well.

Kindest Regards,
Scott M
n/a Points
2014-08-25 8:32 am

Can you tell me why this, placed at the top of my .htaccess file, creates a 500-internal server error?

RewriteEngine onRewriteCond %{HTTP_HOST} ^mydayinuy.com [NC,OR]RewriteCond %{HTTP_HOST} ^www.mydayinuy.com [NC]RewriteRule ^(.*) $ http://mydayinuy.wordpress.com/$1 [L,R=301,NC

Staff
17,456 Points
2014-08-25 11:34 am
Hello Pat,

I am not quite sure why that code fails. I tested it on my own domain and it also failed. The one below was tested with my own domain and worked correctly. I have replaced my domain name with yours, so it should work for you as well.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydayinuy\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mydayinuy\.com$
RewriteRule ^/?$ "http\:\/\/mydayinuy\.wordpress\.com\/" [R=301,L]


Kindest Regards,
Scott M
n/a Points
2014-08-28 10:30 am

I have a question, please anyone out there help me!!

if a user email address like "user@example.com" when form is submitted, it should go to their specific domain name i.e, www.example.com,

same should go for user like "user@gmail.com", this should be automatically go to the www.gmail.com when submit the form is submitted.

simply that have to redirect to the domain name after the @ symbol?

I want my redirect to be to the specific domain names after their @symbols

Thanks in advance

Staff
8,172 Points
2014-08-28 10:36 am
To clarify, it sounds like you want to redirect users to their email provider after they submit a contact form? If so, this can be done with custom PHP form processing through custom code on your site, but cannot be done in a simple manner.
n/a Points
2014-08-28 4:33 pm

Can you please direct me to any custom php code to achieve this project. 

I need a custom to redirect users to their email provider after they submit a contact form?

Staff
17,456 Points
2014-08-29 9:29 am
Hell Remax,

Custom code means that it does not exist and would have to be written from scratch, so there is no code for us to point you to.

Kindest Regards,
Scott M
n/a Points
2014-08-28 3:59 pm

yes, exactly that is what i want to achieve, can you please give me any php script or code to achieve this. I want to redirect  users to their email provider after they submit a contact form?  can you please refer me to a php script or code i can use to achieve this.

 

Thank you in advance

Staff
8,172 Points
2014-08-28 4:18 pm
Unfortunately, this is not something we would be able to write for you and I am unaware of any solutions that exist for this. Basically, you will need to parse the user input with PHP and redirect the user after form submission based on the data provided. If you are not a developer, the best solution would be to hire a developer to code this for you.

I would also like to add that while it is possible, it is not ideal for user experience and can cause a large number of users to become confused and thus cease activity on your site.
n/a Points
2014-08-28 4:37 pm

Thanks, i will appreciate if you can assist me. Just let give me a clue and where to find one good custom php code to make use of

Staff
17,456 Points
2014-08-29 9:30 am
Hello Remax,

Custom code means that there is not an existing script to do what you ask (that we know of.) You will either need to code it yourself or hire someone to do that as a small project.

Kindest Regards,
Scott M
n/a Points
2014-09-01 6:38 am

in my site wordpress is installed in subfolder  http://abcd.chaitanya.com/blog to  http://abcd.com/blog using htaccess with www infront of the site address

Staff
8,172 Points
2014-09-02 1:53 pm
Your comment is a bit unclear. Could you clarify?

Post a Comment

Name:
Email Address:
Phone Number:
Comment:
Submit

Please note: Your name and comment will be displayed, but we will not show your email address.

75 Questions & Comments

Post a comment

Back to first comment | top

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!