我在为一个既有普通版本又有移动版本的网站配置 Apache 时遇到了一些麻烦。这个想法是使用移动浏览器自动将用户重定向到移动版本,如果普通台式电脑上的某人试图连接到移动版本,则将其重定向到普通网站。
现在它将移动用户正确重定向到移动网站。但它似乎无法以其他方式重定向到桌面版本。此外,当您访问网站的移动版时,它会显示默认的“It works!” 出于某种原因页面而不是移动索引页面..
这是我使用的所有配置。希望有人能够帮助我解决这个问题。提前致谢!普通网站:
<VirtualHost *:80>
ServerAdmin webmaster@henal.local
ServerName henal.local
ServerAlias www.henal.local
DocumentRoot /var/www/henal.local
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/henal.local>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
DirectoryIndex index.html
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/deltionkrant/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel debug
CustomLog ${APACHE_LOG_DIR}/deltionkrant/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
.htaccess 普通网站:
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|googlebot- mobile|iemobile|ipad|iphone|ipod|opera mobile|palmos|webos" [NC]
RewriteRule ^$ http://m.henal.local/ [L,R=302]
手机网站:
<VirtualHost *:80>
ServerAdmin webmaster@henal.local
ServerName m.henal.local
ServerAlias henal.local
DocumentRoot /var/www/henal.local/mobile
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/henal.local/mobile>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
DirectoryIndex index.html
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
.htaccess 移动网站:
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} "!(android|blackberry|googlebot- mobile|iemobile|ipad|iphone|ipod|opera mobile|palmos|webos)" [NC]
RewriteRule ^$ http://www.henal.local/ [L,R=302]