问题
When I type in my domain name like without the www
(like http://example.com
), it doesn't work and gives error message. However, when I add the www
to it (like http://www.example.com
), it works.
Isn't it supposed to work both ways (with and without the www
)?
回答1:
All you need is to add the following code to your root .htaccess
file:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
回答2:
With the current version of apache, you need to do the following, which has changed compared to the previous versions:
cd /etc/apache2/sites-enabled
Now find the config file for your domain and edit it (the first three lines after <VirtualHost *:80>
is what we need here):
<VirtualHost *:80>
ServerName www.yourdomain.com
ServerAlias yourdomain.com *.yourdomain.com
ServerAdmin webmaster@localhost
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
</VirtualHost>
And now after saving changes to the file, you should reload Apache we server configuration with:
service apache2 reload
and it'll work!
P.S. You may also want not to add *.yourdomain.com
to the end of your ServerAlias
line.
回答3:
to solve this issue
-> suppose you want mysubdomain.domain1.com
-> goto your dns records settings in your web panel ( cpanel , vestapanel etc ) of domain1.com
-> add there new A record with ip of your domain1.com and fill record/hostname field with @ // @ mean no www if you want www too then add another new A record and replace @ with www
-> save it
-> wait for dns changes to take place maybe take few hours
回答4:
Alternatively, you could follow below steps which solves this problem, for sure, if you're using GoDaddy and google apps :
Go to Google Apps and sign in to domain management.
Then click on domain settings.
Then click on domain Names.
Then Click on words highlighted to set a redirect via google apps and you should see it done within 3 hours or MAX 2 DAYS (though it usually does not take more than a day in the rarest case).Just follow the simple english instructions there and you should see it done.
More details and reference :
http://www.techproceed.com/2014/05/custom-domain-setup-on-blogger-with.html
回答5:
You need to change any full urls to paths. If your php include or other processes are linked using urls, it will only work one way.
$.ajax(
{
url:'/LAYOUT/process.php'
}
as oppose to the full url
$.ajax(
{
url:'https://www.yourdomain.com/LAYOUT/process.php'
}
Using a simple path will allow it to work both ways with or without www.
来源:https://stackoverflow.com/questions/10135456/domain-doesnt-work-without-www