我在magento.stackexchange上发布了这个问题,但没有得到我的解决方案,所以发布在这里。可以查看这个link。我希望该用户可以访问我的网站有或没有www.But它无法使用www。 我的网站从地址中删除www并重定向到非{www {}等地址,在htaccess中为www编写此代码,但无效。
RewriteCond %{http_host} ^babycave.co.uk [NC]
RewriteRule ^(.*) http://www.babycave.co.uk/$1 [L,R=301]
任何人都可以指导我问题所在吗?从管理员方面我设置了安全和不安全的网址,如http://babycave.co.uk/
。谢谢
以下是我的htaccess文件:
## uncomment these lines for CGI mode
## make sure to specify the correct cgi php binary file name
## it might be /cgi-bin/php-cgi
# Action php5-cgi /cgi-bin/php5-cgi
# AddHandler php5-cgi .php
############################################
## GoDaddy specific options
# Options -MultiViews
## you might also need to add this line to php.ini
## cgi.fix_pathinfo = 1
## if it still doesn't work, rename php.ini to php5.ini
############################################
## this line is specific for 1and1 hosting
#AddType x-mapp-php5 .php
#AddHandler x-mapp-php5 .php
############################################
## default index file
DirectoryIndex index.php
<IfModule mod_php5.c>
############################################
## adjust memory limit
# php_value memory_limit 64M
php_value memory_limit 256M
php_value max_execution_time 18000
############################################
## disable magic quotes for php request vars
php_flag magic_quotes_gpc off
############################################
## disable automatic session start
## before autoload was initialized
php_flag session.auto_start off
############################################
## enable resulting html compression
#php_flag zlib.output_compression on
###########################################
# disable user agent verification to not break multiple image upload
php_flag suhosin.session.cryptua off
###########################################
# turn off compatibility with PHP4 when dealing with objects
php_flag zend.ze1_compatibility_mode Off
</IfModule>
<IfModule mod_security.c>
###########################################
# disable POST processing to not break multiple image upload
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
<IfModule mod_deflate.c>
############################################
## enable apache served files compression
## http://developer.yahoo.com/performance/rules.html#gzip
# Insert filter on all content
###SetOutputFilter DEFLATE
# Insert filter on selected content types only
#AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
# Netscape 4.x has some problems...
#BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
#BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
#BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# Don't compress images
#SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
# Make sure proxies don't deliver the wrong content
#Header append Vary User-Agent env=!dont-vary
</IfModule>
<IfModule mod_ssl.c>
############################################
## make HTTPS env vars available for CGI mode
SSLOptions StdEnvVars
</IfModule>
<IfModule mod_rewrite.c>
############################################
## enable rewrites
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^babycave.co.uk$
RewriteRule (.*) http://www.babycave.co.uk$1 [R=301]
############################################
## you can put here your magento root folder
## path relative to web root
#RewriteBase /magento/
############################################
## uncomment next line to enable light API calls processing
# RewriteRule ^api/([a-z][0-9a-z_]+)/?$ api.php?type=$1 [QSA,L]
############################################
## rewrite API2 calls to api.php (by now it is REST only)
RewriteRule ^api/rest api.php?type=rest [QSA,L]
############################################
## workaround for HTTP authorization
## in CGI environment
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
############################################
## TRACE and TRACK HTTP methods disabled to prevent XSS attacks
RewriteCond %{REQUEST_METHOD} ^TRAC[EK]
RewriteRule .* - [L,R=405]
############################################
## redirect for mobile user agents
#RewriteCond %{REQUEST_URI} !^/mobiledirectoryhere/.*$
#RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
#RewriteRule ^(.*)$ /mobiledirectoryhere/ [L,R=302]
############################################
## always send 404 on missing files in these folders
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
############################################
## never rewrite for existing files, directories and links
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
############################################
## rewrite everything else to index.php
RewriteRule .* index.php [L]
</IfModule>
############################################
## Prevent character encoding issues from server overrides
## If you still have problems, use the second line instead
AddDefaultCharset Off
#AddDefaultCharset UTF-8
<IfModule mod_expires.c>
############################################
## Add default Expires header
## http://developer.yahoo.com/performance/rules.html#expires
ExpiresDefault "access plus 1 year"
</IfModule>
############################################
## By default allow all access
Order allow,deny
Allow from all
###########################################
## Deny access to release notes to prevent disclosure of the installed Magento version
<Files RELEASE_NOTES.txt>
order allow,deny
deny from all
</Files>
############################################
## If running in cluster environment, uncomment this
## http://developer.yahoo.com/performance/rules.html#etags
#FileETag none
答案 0 :(得分:2)
在PLesk
中检查您的配置(假设您有Plesk 11.x)
在Plesk admin中 - &gt;您的域名 - &gt; “托管设置”选中“Preffered Domain”选项。
我的设置中的默认选项是“domain.tld
”。
您可以将其更改为“www.domain.tld
”并检查问题是否已修复。
答案 1 :(得分:2)
这里有一些可能的问题。
服务器设置:
您的网络服务器需要配置为除了www。别名。
我不确定你是如何通过plesk这样做的,但我建议检查你的apache和dns设置,以确保它们都配置为同时处理example.com和www.example.com
在Apache中,您可以使用以下语句在vhost部分执行此操作
ServerName example.com
ServerAlias www.example.com
MAGENTO SETTINGS :
您无需修改magento提供的默认htaccess,因为它将同时接受www.example.com和example.com。
但是,Magento会将URL重写为以下数据库表中设置的内容。core_config_data 在路径下
网/不安全/ BASE_URL 和 网/安全/ BASE_URL
因此,两个地址都可以到达您的商店,但一个地址需要默认,而magento将始终重写该地址。
答案 2 :(得分:-1)
这会将babycave.co.uk
重定向到www.babycave.co.uk
RewriteCond %{HTTP_HOST} !^www.babycave.co.uk$ [NC]
RewriteRule ^(.*)$ http://www.babycave.co.uk/$1 [L,R=301]