- 注册
- 2019-09-05
- 消息
- 2,007
- 反馈评分
- 1,622
- 点数
- 113
-
Windows 10 Chrome 93.0.4577.63
- #1
根据XenForo提供的伪静态
Apache伪静态:
默认为根目录下的htaccess.txt文件中的内容,一般网站根目录直接存在Apache的
内容如:
Nginx伪静态:
由于Nginx伪静态配置文件语法与Apache不同,以宝塔面板为例,该文件位于
内容如下:
其中
另外
注意:
htaccess.txt
中的伪静态规则,如果你要隐藏/index.php?
地址,则需要在后台>设置>选项>基本信息
中选择使用最佳URLs
。这样访问的地址就会直接隐藏/index.php?
地址,如:https://yourdomain.com/index.php?whats-new/
变为 https://yourdomain.com/whats-new/
默认为根目录下的htaccess.txt文件中的内容,一般网站根目录直接存在Apache的
.htaccess
伪静态文件。Apache开启伪静态需要开启LoadModule rewrite_module modules/mod_rewrite.so
模块,然后重启Apache生效。内容如:
Apache 配置:
# Mod_security can interfere with uploading of content such as attachments. If you
# cannot attach files, remove the "#" from the lines below.
#<IfModule mod_security.c>
# SecFilterEngine Off
# SecFilterScanPOST Off
#</IfModule>
ErrorDocument 401 default
ErrorDocument 403 default
ErrorDocument 404 default
ErrorDocument 405 default
ErrorDocument 406 default
ErrorDocument 500 default
ErrorDocument 501 default
ErrorDocument 503 default
<IfModule mod_rewrite.c>
RewriteEngine On
# If you are having problems with the rewrite rules, remove the "#" from the
# line that begins "RewriteBase" below. You will also have to change the path
# of the rewrite to reflect the path to your XenForo installation.
#RewriteBase /xenforo
# This line may be needed to workaround HTTP Basic auth issues when using PHP as a CGI.
#RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
</IfModule>
由于Nginx伪静态配置文件语法与Apache不同,以宝塔面板为例,该文件位于
/www/server/panel/vhost/rewrite/yourdomain.com.conf;
,宝塔面板自带伪静态配置功能。Nginx自带伪静态功能,无需重启。内容如下:
NGINX:
location / {
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?s=$1 last; break;
}
}
location ~ ^/(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt)/ {
deny all;
return 404;
}
return 404;
为404错误代码,返回404错误页面,该页面根据Nginx的网站配置开启error_page 404 /404.html;
,当然也可返回其他错误代码。另外
data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt
是禁止访问目录及文件,用竖线|
分割。注意:
data/|js/|styles/|install/
目录加上斜线/
表示禁止访问目录,不加斜线/
表示禁止访问目录中的文件,这会造成网站一些文件无法加载。