3

I don't know much anything about how hosting works, so if there's any additional info I should provide, please let me know.

The URL example.com correctly forwards to www.example.com. But example.com/file.pdf and example.com/some-blog-post also forwards to www.example.com rather than www.example.com/file.pdf and www.example.com/some-blog-post as I'd like them to.

How can I set this up properly?

I'm hosting my personal website on GitHub pages, with a custom domain name through Namecheap. My current set up is the following:

Host Name   IP Address / URL        Record Type
@           http://www.example.com  URL Redirect
www         example.github.io       CNAME (Alias)

And the GitHub repository "example.github.io" contains a CNAME file at the top level that just contains the text

www.example.com
1
+50

You have implemented this redirect with Namecheap. Their help document explains how to set up the redirects either way:

www1  http://destination.com      Permanent (301)
www2  http://destination.com/     Permanent (301)

In the above case, www1.yourdomain.com will not pass values to the destination URL so, www1.yourdomain.com/xyz.html will redirect users to http://destination.com only.

On the otherhand, www2.yourdomain.com/xyz.html will redirect users to http://destination.com/xyz.html (pay attention to the / in the configuration).

So in Namecheap's interface, you need to ensure that your redirect rules have a trailing slash on the destination.

  • I missed that point in the docs. I even got on tech support with them, and it was never mentioned by the agent who helped me! I'll try it when I get home and update with results. – shadowtalker Sep 29 '15 at 20:22
  • Changing http://www.example.com to http://www.example.com/ worked! It's in the details... – shadowtalker Sep 30 '15 at 0:40
1

What you could do is make example.com and www.example.com as separate URLs pointing to two different folders on the server, but make www.example.com point to the folder with the website contents.

Then these lines can be added to apache's main configuration file (httpd.conf) if you have mod_rewrite installed.

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

Just make sure they are added before custom RewriteRule lines are processed for the example.com website if any.

0

First of all,you need to know type of content. redirection is perfect. If you are redirecting based on server config(Apache), it is perfect. example.com/file.pdf deposit as file and its source is example.com so example.com redirect to www.example.com as deposit content as pdf

Upto this level,it is working fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.