欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php设置伪静态问题

程序员文章站 2024-04-05 17:08:42
...
在设置伪静态时一直不能成功(rewrite组件已经打开)httpd-vhosts.conf配置是
DocumentRoot "E:/daima/htdocs/virtual"
ServerName www.lhb.com
#Directory节点指定该目录下的文件,图片的访问权限
#设置虚拟主机的错误页面,欢迎页面

Order allow,deny
Allow from all

#是否列出文件目录(None不显示Indexes显示目录)
Options Indexes
#设置错误页面
errorDocument 404 /error.html
#设置首页面
DirectoryIndex index.html
#AllowOverride All
#配置rewrite
RewriteEngine on
RewriteRule aaa.html news.php


去掉RewriteEngine on
RewriteRule aaa.html news.php错误页面,首页面均能正确显示,带入那2行代码,在浏览器输入www.lhb.com/aaa.html则报错:You don't have permission to access / on this server.


回复讨论(解决方案)

用的Apache?为什么不用.htaccess文件呢?
写apache配置文件里多麻烦,有改动还得重启服务。

用的Apache?为什么不用.htaccess文件呢?
写apache配置文件里多麻烦,有改动还得重启服务。


用.htaccess也不行啊
.htaccess代码:
Options FollowSymLinks
RewriteEngine on
RewriteRule RewriteRule aaa.html news.php

httpd-vhosts.conf代码

DocumentRoot "E:/daima/htdocs/virtual"
ServerName www.lhb.com
#Directory节点指定该目录下的文件,图片的访问权限
#设置虚拟主机的错误页面,欢迎页面

Order allow,deny
Allow from all

#是否列出文件目录(None不显示Indexes显示目录)
Options Indexes
#设置错误页面
errorDocument 404 /error.html
#设置首页面
DirectoryIndex index.html
AllowOverride All
#配置rewrite



首页面 错误页面能够访问 访问http://www.lhb.com/aaa.html就是aaa.html的内容也不能实现伪静态

RewriteEngine OnRewriteRule ^aaa\.html news.php [NC]

RewriteEngine OnRewriteRule ^aaa\.html news.php [NC]


RewriteEngine OnRewriteRule ^aaa\.html news.php [NC]

按照你这种设置,http://www.lhb.com/aaa.html也会报错:You don't have permission to access / on this server.

虽然不知道为啥,但把配置文件httpd-vhosts.conf里的Options None选项去掉就可以实现伪静态了