Url 重写在 WAMP 子域中不起作用
Url rewriting not working in WAMP Subdomain
我在 WAMP 服务器下为移动网站创建了一个子域,它使用 IP 地址作为域名 192.168.106.1
但问题是,当我尝试在 .htaccess
文件中重写 url 时,我无法工作。我使用了一个复制的 .htaccess
文件,它适用于 localhost
以下是我的 httpd.conf
文件
中域名的服务器配置
<VirtualHost 192.168.106.1>
#LoadModule rewrite_module modules/mod_rewrite.so
# The name to respond to
ServerName m.localhost
# Folder where the files live
DocumentRoot "C:/wamp/www/mobile/"
# A few helpful settings...
<Directory "C:/wamp/www/mobile/">
Allow from all
Order Allow,Deny
# Enables .htaccess files for this site
AllowOverride All
</Directory>
# Apache will look for these two files, in this order, if no file is specified in the URL
DirectoryIndex index.html index.php
</VirtualHost>
我也删除了第二行的评论标签,但它仍然不起作用。
谁有解决办法吗?
这是一个解决方案
首先确保您转到 C:/wamp/bin/apache/YOUR APACHE VERSION/conf
并打开 httpd.conf
文件并取消注释此行
#Include conf/extra/httpd-vhosts.conf
所以它看起来像这样
Include conf/extra/httpd-vhosts.conf
然后也打开位于 C:/windows/System32/drivers/etc
的 host
文件并添加这个(你的 IP 地址到配置)
#add the sub-domain name, in this case I use mobile, it can be anything
192.168.106.1 mobile.localhost
192.168.106.1 192.168.106.1
然后最后也是最重要的,打开 C:/wamp/bin/apache/YOUR APACHE VERSION/conf/extra/httpd-vhosts.conf
中的 vhost
文件并将其添加到文件
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/mobile"
ServerName m.localhost
Options Indexes FollowSymLinks
<Directory "C:/wamp/www/mobile">
AllowOverride All
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
#If you want to allow access from your internal network
# For specific ip addresses add one line per ip address
Allow from 192.168.106.1
# For every ip in the subnet, just use the first 3 numbers of the subnet
#Allow from 192.168.0
</Directory>
</VirtualHost>
然后重新启动您的 WAMP 服务器,它就可以工作了
我在 WAMP 服务器下为移动网站创建了一个子域,它使用 IP 地址作为域名 192.168.106.1
但问题是,当我尝试在 .htaccess
文件中重写 url 时,我无法工作。我使用了一个复制的 .htaccess
文件,它适用于 localhost
以下是我的 httpd.conf
文件
<VirtualHost 192.168.106.1>
#LoadModule rewrite_module modules/mod_rewrite.so
# The name to respond to
ServerName m.localhost
# Folder where the files live
DocumentRoot "C:/wamp/www/mobile/"
# A few helpful settings...
<Directory "C:/wamp/www/mobile/">
Allow from all
Order Allow,Deny
# Enables .htaccess files for this site
AllowOverride All
</Directory>
# Apache will look for these two files, in this order, if no file is specified in the URL
DirectoryIndex index.html index.php
</VirtualHost>
我也删除了第二行的评论标签,但它仍然不起作用。
谁有解决办法吗?
这是一个解决方案
首先确保您转到 C:/wamp/bin/apache/YOUR APACHE VERSION/conf
并打开 httpd.conf
文件并取消注释此行
#Include conf/extra/httpd-vhosts.conf
所以它看起来像这样
Include conf/extra/httpd-vhosts.conf
然后也打开位于 C:/windows/System32/drivers/etc
的 host
文件并添加这个(你的 IP 地址到配置)
#add the sub-domain name, in this case I use mobile, it can be anything
192.168.106.1 mobile.localhost
192.168.106.1 192.168.106.1
然后最后也是最重要的,打开 C:/wamp/bin/apache/YOUR APACHE VERSION/conf/extra/httpd-vhosts.conf
中的 vhost
文件并将其添加到文件
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/mobile"
ServerName m.localhost
Options Indexes FollowSymLinks
<Directory "C:/wamp/www/mobile">
AllowOverride All
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
#If you want to allow access from your internal network
# For specific ip addresses add one line per ip address
Allow from 192.168.106.1
# For every ip in the subnet, just use the first 3 numbers of the subnet
#Allow from 192.168.0
</Directory>
</VirtualHost>
然后重新启动您的 WAMP 服务器,它就可以工作了