0

Our previous website has one sub directory called "mobile". So in the main pages we write code if it is screen size less than 640px then go to mobile/ folder .

<link href="http://mobile.example.com/index.html/" media="only screen and (max-width: 640px)" rel="alternate" />

For example, someone takes example.com/index.html website from mobile, they are redirected to mobile.example.com/index.html.

Now we developed a new website that is responsive & in that files we remove the redirection code. But some people bookmarked our previous mobile page url .

So we want to redirect all mobile.example.com/file to example.com/file.

How can we do this?

1
  • 1
    You may be using a "subdirectory" in your underlying file system implementation, but your example shows a subdomain, not a subdirectory. Also, the HTML snippet you show does not a trigger a "redirect", which you seem to imply?
    – MrWhite
    Commented Nov 19, 2017 at 22:48

1 Answer 1

2

Based very specifically on the information that you provided in your question, all you need to do is create a file called .htaccess in the doc root (web / httpdocs / www folder) of mobile.example.com (inside your "mobile" directory) and put in the code below. Be sure to add the most relevant version that best fits your circumstances, as indicated below:

1. Preferred version of your domain's URL is "non-www"

Options +FollowSymlinks  
RewriteEngine on  
RewriteRule ^index.html(.*)$ http://example.com/index.html$1 [R=301,NC]

2. Preferred version of your domain's URL is the "www" version

Options +FollowSymlinks  
RewriteEngine on  
RewriteRule ^index.html(.*)$ http://www.example.com/index.html$1 [R=301,NC]

As for redirecting individual pages to other individual pages, as long as the URLs are identical, and the only difference is the mobile subdomain, then you should be good to go. I have not tested this, please provide feedback!

On the other hand, if URIs for each individual directory (i.e. /directory/) or page (i.e. /page.html) on your old mobile version are different than the non-mobile version, all that you would need to..

Page to Page Redirect from subdomain:

Redirect 301 "/old-page.html" "http://www.example.com/new-page.html"

Remember, this is all taking place on the .htaccess file you created within the mobile folder.

3
  • @MrWhite would you mind telling me how to properly format the information in my answer - I cannot decipher how to modify correctly in future answers. Thank you for your time & help! Commented Nov 21, 2017 at 4:44
  • You can view my edits by checking the edit history on your answer (use the "side-by-side markdown" option). When editing your answer you can click the ? (help menu) to get more editing help. From there you can also get advanced help. The main reason for my edit was that you had formatted your blocks of code as "quotations", rather than "code blocks" (indent by 4 spaces) - this option is on the toolbar. Apart from being harder to read, some characters can get omitted.
    – MrWhite
    Commented Nov 21, 2017 at 10:01
  • I did review your edits, and knew that the highlighted color had changed, but you answered my question in the latter part of your comment. Thanks for your help! Commented Nov 21, 2017 at 10:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.