我试图通过。htaccess为我的网站设置重写规则。当通过域名(如-
)访问时,它可以正常工作http://www.example.com/admin/my/virtual/path问题是当我尝试通过IP地址访问时,它返回404页。
我绑定IP与我的虚拟路径,因为当我访问http://192.168.1.2/时,它显示http://www.example.com/admin/页面,即管理员的主页,没有任何问题。
下面的链接不工作,返回404页面-
http://192.168.1.2/my/virtual/path我猜是。htaccess问题。这是我的。htaccess代码供参考
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ index.php [L]
# The following rewrites all other queries to index.php. The
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::'2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^([^?]*)$ %{ENV:BASE}index.php [NC,L]
这是我的vhost配置IP -
<VirtualHost xxx.xxx.xxx.xxx:80>
DocumentRoot /path/of/my/hosting/location/public_html/admin
<Directory "/path/of/my/hosting/location/public_html/admin">
allow from all
Options None
Require all granted
</Directory>
</VirtualHost>
这是我的域名托管部分-
<VirtualHost example.com:80>
DocumentRoot /path/of/my/hosting/location/public_html
<Directory "/path/of/my/hosting/location/public_html">
allow from all
Options +FollowSymLinks
allowoverride all
Require all granted
HostNameLookups on
</Directory>
ServerName example.com
ServerAlias www.example.com
</VirtualHost>
域名的vhost部分有allowoverride all
,这告诉apache允许对.htaccess
进行更改,但是ip的vhost部分没有。
将allowoverride all
添加到ip
虚拟主机块中,应该可以了。
<VirtualHost xxx.xxx.xxx.xxx:80>
DocumentRoot /path/of/my/hosting/location/public_html/admin
<Directory "/path/of/my/hosting/location/public_html/admin">
allowoverride all
allow from all
Options None
Require all granted
</Directory>
</VirtualHost>