我在爲具有普通和移動版本的網站配置Apache時遇到了一些麻煩。這個想法是將用戶通過手機瀏覽器自動重定向到移動版本,如果普通臺式機上的某個人正在嘗試連接到移動版本,將其重定向到正常網站。爲移動網站配置Apache的問題
現在它正確地將移動用戶重定向到移動網站。但似乎無法將其他方式重定向到桌面版本。另外,當你轉到網站的移動版本時,它會顯示默認的「It works!」。由於某種原因,而不是移動索引頁。
這裏是我使用的所有配置。希望有人能夠幫助我解決這個問題。提前致謝! 普通網站:
<VirtualHost *:80>
ServerAdmin [email protected]
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 [email protected]al
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移動網站:
感謝您的迴應!這主要是一個學校示範,所以它不會被用於公共網站(儘管我可以創建一個更好的解決方案,爲您的真正的公共場所提供您的提示!)。這也是爲什麼我這樣配置它。 真的很感謝您的提示,並將爲未來的項目採取這些要點。 :) – Gladen
但我嘗試刪除引號並將2個標誌添加到.htaccess。我再次測試它,但它沒有任何區別。關於「It works」頁面,是的,我正在使用瀏覽器在我配置Apache(虛擬Ubuntu)的計算機上進行測試。我編輯hosts文件,以便henal.local和m.henal.local引用127.0.0.1所以也許這是原因?雖然正常的網站似乎工作得很好.. – Gladen
好吧,所以你需要使用移動瀏覽器進行測試。通過上述配置,如果您在桌面瀏覽器中輸入m.henal.local,那麼它將重定向到henal.local。由於您的DNS無法從外部解析,因此您將無法使用手機進行測試。相反,爲什麼不嘗試Android模擬器:http://developer.android.com/guide/developing/devices/emulator.html –