: How to show different pages for www and non-www versions A simple (probably stupid) question: is it possible to show different pages for www and non-www versions of a website? I mean for example,
A simple (probably stupid) question: is it possible to show different pages for www and non-www versions of a website?
I mean for example, example.com will show the content in /mainfolder and domain.com will show the content in /secondfolder.
I don't want to redirect, like if the user goes to domain.com he will be redirected to domain.com/www - I don't want that, I just wanna know how to show 2 different index.html files, one for the www version of the website and one for the version without
Or if possible, how can I create the www subdomain in cPanel (as it won't let me) - any way to override this?
UPDATE
I tried this .htaccess edit and it worked partially:
RewriteCond %{HTTP_HOST} =www.site.com
RewriteRule ^(.*)$ site.com/folder/ [P]
It now shows the contents of site.com/folder when users access site.com however it doesn't load the CSS of the page - any way to fix this?
More posts by @Martha676
2 Comments
Sorted by latest first Latest Oldest Best
Just found the solution:
RewriteCond %{HTTP_HOST} ^www.site.com$
RewriteCond %{REQUEST_URI} !^/folder/
RewriteRule (.*) /folder/
Yes, this is definitely possible. But please note that, by convention, domain.com is just an alias for domain.com. So, what you describe is not at all standard and violates most users' expectations. It also runs at least some risk of search engine penalties. So, in my opinion, it is not a good idea, but yes, it's possible.
Exactly how you do it depends on the server and/or scripting technology. For example, you could do it with Apache, which would look like this (in a .htaccess file):
RewriteCond %{HTTP_HOST} RewriteCond %{REQUEST_URI} !^/whatever/?
RewriteRule . /whatever
This would send all requests for domain.com to /whatever, but would not affect requests on domain.com. This is probably overly simplistic for what you want, but you haven't provided a lot of detail.
You can do the same thing in a scripting language like Python or PHP, but how you do it depends on what exactly you want to do.
Also, the reason you can't create a www subdomain in cPanel is that it creates it automatically.
(Edited: forgot to add the second RewriteCond to avoid a loop.)
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.