• 欢迎 游客 您的光临,下载之前请先阅读 积分规则 。任何技术问题请在论坛提问,本站定制插件、模板主题。售前、售后问题请联系QQ:5916171
    本站自由发布资源可赚取积分及人民币(可提现)(保证资源真实可用,如被举报封号处理。谨慎分布)。
  • 即日起发表主题、回帖、发布&更新资源、创建&回复私信、发布&回复个人动态均需要验证手机号码,其它不受影响。如不便可进群提问。点击链接加入群聊【XenForo讨论社区】:群号1:143277648

技巧教程 XenForo中的Nginx、Apache服务器伪静态设置

UID
875
注册
2020/06/14
消息
37
黄金
3G
根据XenForo提供的伪静态htaccess.txt中的伪静态规则,如果你要隐藏/index.php?地址,则需要在后台>设置>选项>基本信息中选择使用最佳URLs 。这样访问的地址就会直接隐藏/index.php?地址,如:https://itcbbs.ink/index.php?/ 变为 https://itcbbs.ink/

Apache伪静态:
默认为根目录下的htaccess.txt文件中的内容,一般网站根目录直接存在Apache的.htaccess伪静态文件。Apache开启伪静态需要开启LoadModule rewrite_module modules/mod_rewrite.so 模块,然后重启Apache生效。
内容如:
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伪静态:
由于Nginx伪静态配置文件语法与Apache不同,以宝塔面板为例,该文件位于/www/server/panel/vhost/rewrite/yourdomain.com.conf;,宝塔面板自带伪静态配置功能。Nginx自带伪静态功能,无需重启。
内容如下:
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/目录加上斜线/表示禁止访问目录,不加斜线/表示禁止访问目录中的文件,这会造成网站一些文件无法加载。

设置好后,打开后台的 最佳url如果能访问除版面列表之外的页面,则表示设置成功
 
最后编辑:
后退
顶部 底部