zoukankan      html  css  js  c++  java
  • 在独立服务器上通过Ubuntu 18.04+apache2+php5.6+mysql5.7+discuz!x3.4搭建的论坛实现伪静态的正确方法

    1.参考如下帖子,了解如何配置伪静态的一般流程

    [修改] linux,IIS,WIN主机,虚拟主机,Nginx主机DZX2.5 X2伪静态规则文件下载 教程

     转 https://www.discuz.net/thread-2489176-1-1.html

    下载在最下面

    太多人在问伪静态规则文件的问题了,我也是小白,在这里简单的说一下默认情况下的伪静态规则文件的创建方法

    首先,进入后台:SEO设置,伪静态设置


    这里是伪静态设置,建议保持默认


    然后勾选后面的框


    然后点击提交

    点此查看规则:

    然后 点击这个 去查看规则(在此过程中不要关掉后台)

    然后选择适合你的规则,复制到文本文档,然后另存为:WIN主机就另存为httpd.ini    Linux主机就另存为:.htaccess(文件名为空哟),其他主机我也不是很清楚了


    需要说明的是,如果你的网站不是放在根目录的,就需要增添一个目录路径哟

    1. Apache Web Server(虚拟主机用户)
    2. # 将 RewriteEngine 模式打开
    3. RewriteEngine On
    4. # 修改以下语句中的 /discuz 为你的论坛目录地址,如果程序放在根目录中,请将 /discuz 修改为 /
    5. RewriteBase /discuz
    复制代码

    安装在子目录的,需要把discuz改成你自己的子目录,不过这里希望大家理解一下“根目录”

    比如,网站:http://www.chinagirlol.com   以及网站http://www.chinagirlol.com/bbs   后者叫子目录,但是===如果你给bbs目录绑定了域名bbs.chinagirlol.com 那bbs这个目录就是bbs.chinagirlol.com的根目录,那伪静态就应该是  把RewriteBase /discuz 改成RewriteBase /




    下载(本来不准备发的,有些人就是懒得不得了;上面的教程已经写清楚了,如果实在是懒得做,就花钱下载吧):

    这是DZX2的,可适用于大部分情况的虚拟主机和IIS主机


    DZX2.5,可适用于大部分情况的虚拟主机和IIS主机


    有部分人安装正确的设置方法,设置了伪静态也还是不能实现伪静态,可以参考一下我置顶的这个回复,171楼 。另外还需要注意一个问题,需要给伪静态规则文件设置访问权限



    171楼:http://www.discuz.net/forum.php? ... 489176&pid=24627204

    其他教程:

    去掉附件下载提示 For Discuz! X2.0 X2.5
    http://www.discuz.net/thread-2891700-1-1.html


    真正正确的官方主帖下方的“更多”分享按钮 修改方法 支持DZX2 X2.5
    http://www.discuz.net/thread-2481632-1-1.html

    linux,IIS,WIN主机,虚拟主机,Nginx主机DZX2.5 X2伪静态规则文件下载 教程
    http://www.discuz.net/thread-2489176-1-1.html


    【ChinaGirl】仿19楼 帖内游客注册提醒/QQ/新浪微博账号登陆 For 7.2/X2/X2.5
    http://www.discuz.net/thread-2617671-1-1.html


    DZX2.0~DZX2.5友情链接横排显示,图片带描述文字友情链接横排显示
    http://www.discuz.net/thread-2668687-1-1.html


    【DZ教程之备份数据】利用帝国备份王备份数据库,搬家教程
    http://www.discuz.net/thread-2743633-1-1.html

     2.在站点根目录上添加web.config,内容如下:

    这是我在一个群里的朋友帮我解决的,在这把代码分享一下,以后碰到我这种问题的友友们也可以借鉴一下:

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                    <rule name="topic">
                        <match url="^topic-(.+).html$" />
                        <action type="Rewrite" url="portal.php?mod=topic&amp;topic={R:1}" />
                    </rule>
                    <rule name="article">
                        <match url="article-([0-9]+).html$" />
                        <action type="Rewrite" url="portal.php?mod=view&amp;aid={R:1}" />
                    </rule>
                    <rule name="forum">
                        <match url="^forum-([0-9]+)-([0-9]+).html$" ignoreCase="false" />
                        <action type="Rewrite" url="forum.php?mod=forumdisplay&amp;fid={R:1}&amp;page={R:2}" appendQueryString="false" />
                    </rule>
                    <rule name="thread">
                        <match url="^thread-([0-9]+)-([0-9]+)-([0-9]+).html$" />
                        <action type="Rewrite" url="forum.php?mod=viewthread&amp;tid={R:1}&amp;extra=page={R:2}&amp;page={R:3}" />
                    </rule>
                    <rule name="group">
                        <match url="^group-([0-9]+)-([0-9]+).html$" />
                        <action type="Rewrite" url="forum.php?mod=group&amp;fid={R:1}&amp;page={R:2}" />
                    </rule>
                    <rule name="space">
                        <match url="^space-(username|uid)-(.+).html$" />
                        <action type="Rewrite" url="home.php?mod=space&amp;{R:1}={R:2}" />
                    </rule>
                    <rule name="Xrewrite">
                        <match url="^([a-z]+)-(.+).html$" />
                        <action type="Rewrite" url="{R:1}.php?rewrite={R:2}" />
                    </rule>
                </rules>
            </rewrite>
      <asp scriptErrorSentToBrowser="true" />
      </system.webServer>
    <system.web>
    <globalization requestEncoding="utf-8" responseEncoding="utf-8" fileEncoding="utf-8" />
    </system.web>
    </configuration>
    <configuration>
    <system.webServer>
    <rewrite>
        <rules>
            <rule name="Enforce canonical hostname" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTP_HOST}" negate="true" pattern="^www.5-123.com$" />
                </conditions>
                <action type="Redirect" url="http://www.5-123.com/{R:1}" redirectType="Permanent" />
            </rule>
        </rules>
    </rewrite>
    </system.webServer>
    <system.webServer>
            <httpErrors errorMode="Detailed" />
            <asp scriptErrorSentToBrowser="true"/>
        </system.webServer>
        <system.web>
            <customErrors mode="Off"/>
            <compilation debug="true"/>
    </system.web>
    </configuration>


    把以上代码复制下来,用记事本另存为:web.config 格式文件,上传到空间根目录再开启伪静态就好了

    3.根据服务器空间类型选择正确的伪静态方式

    通过在网站根目录下添加添加上面web.config文件,虽然解决了帖子分类,文章内容等链接的404错误,但是在新发布帖子时,还会报404错误,下面为具体解决方法:

    Discuz!系列教程-通过判断空间类型选择伪静态方

    https://www.discuz.net/thread-3191765-1-1.html

    如果是apache2独立服务器多域名时,discuz!伪静态的配置如果按上面的方法修改站点根目录下的.htaccess经过测试发现是无效,正确的修改是服务器下/etc/apache2/sites-available/x.y.z(域名).conf的配置如下(红色部分为添加内容):

    <VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    ServerName bbs.52iss.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/discuz

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/bbs.52iss.com-error.log
    CustomLog ${APACHE_LOG_DIR}/bbs.52iss.com-access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf

    #RewriteEngine on
    #RewriteCond %{HTTPS} !=on
    #RewriteRule ^(.*) https://%{SERVER_NAME}$1 [L,R=301]
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{QUERY_STRING} ^(.*)$
    RewriteRule ^(.*)/topic-(.+).html$ $1/portal.php?mod=topic&topic=$2&%1
    RewriteCond %{QUERY_STRING} ^(.*)$
    RewriteRule ^(.*)/article-([0-9]+)-([0-9]+).html$ $1/portal.php?mod=view&aid=$2&page=$3&%1
    RewriteCond %{QUERY_STRING} ^(.*)$
    RewriteRule ^(.*)/forum-(w+)-([0-9]+).html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3&%1
    RewriteCond %{QUERY_STRING} ^(.*)$
    RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+).html$ $1/forum.php?mod=viewthread&tid=$2&extra=page\%3D$4&page=$3&%1
    RewriteCond %{QUERY_STRING} ^(.*)$
    RewriteRule ^(.*)/group-([0-9]+)-([0-9]+).html$ $1/forum.php?mod=group&fid=$2&page=$3&%1
    RewriteCond %{QUERY_STRING} ^(.*)$
    RewriteRule ^(.*)/space-(username|uid)-(.+).html$ $1/home.php?mod=space&$2=$3&%1
    RewriteCond %{QUERY_STRING} ^(.*)$
    RewriteRule ^(.*)/blog-([0-9]+)-([0-9]+).html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3&%1
    RewriteCond %{QUERY_STRING} ^(.*)$
    RewriteRule ^(.*)/(fid|tid)-([0-9]+).html$ $1/index.php?action=$2&value=$3&%1
    RewriteCond %{QUERY_STRING} ^(.*)$
    RewriteRule ^(.*)/([a-z]+[a-z0-9_]*)-([a-z0-9_-]+).html$ $1/plugin.php?id=$2:$3&%1
    </IfModule>

    </VirtualHost>

    然后重启apache2

    sudo service apache2 restart

    然后发帖,就不会报404错误了。

    当然还得在discuz后台选择所有的伪静态如下:

  • 相关阅读:
    Vector Dictionary HashMap
    崩溃java (打印当前类的地址)
    colspan、rowspan的使用
    基础操作
    安装vuex-devtools插件
    在使用Vuex插件进行状态管理的步骤
    运行cnpm run dev出现错误解决办法
    在使用vue开发时,文件路径的引用(给文件起别名)
    下载脚手架vue.cli出现的问题
    什么是闭包?
  • 原文地址:https://www.cnblogs.com/it-tsz/p/13837896.html
Copyright © 2011-2022 走看看