Pseudo-static configuration and use in Apache (Apache virtual host under Discuz pseudo static) _linux

Source: Internet
Author: User
One opens the Apache configuration file httpd.conf.
Two will #loadmodule Rewrite_module Modules/mod_rewrite front of the # Remove
Three Add in httpd.conf:
<ifmodule mod_rewrite.c>
Rewriteengine on
#RewriteCond%{env:script_url} (?: Index|dispbbs) [ -0-9]+\.html
Rewriterule ^ (. *? (?: Index|dispbbs))-([ -0-9]+) \.html$ $1.php?__is_apache_rewrite=1&__rewrite_arg=$2
</IfModule>

Four to implement the ASP post URL to the PHP post map, in the third step between the <ifmodule mod_rewrite.c> and </IfModule> add:
Rewritemap toLowerCase Int:tolower
Rewritecond%{query_string} (?: Boardid|page|id|replyid|star|skin) \=\d+ [NC]
Rewriterule ^ (. * (?: Index|dispbbs)) \.asp$ $1.php?${tolowercase:%{query_string}}&__is_apache_rewrite=1

Five save httpd.conf and restart Apache.

Vi. Brief introduction of Mod_rewrite
Rewirte's main function is to implement the URL of the jump and hide the real address, based on the Perl language regular expression specifications. Usually help us achieve pseudo static, quasi directory, domain name jump, prevent hotlinking and so on

Vii. use of mod_rewrite rules

Rewriteengine on
Rewritecond%{http_host}!^www.php100.com [NC]
Rewriterule ^/(. *) http://www.php100.com/[L]
--------
Rewriteengine on
Rewriterule ^/test ([0-9]*). html$/test.php?id=$1
Rewriterule ^/new ([0-9]*)/$/new.php?id=$1 [R]

Viii. mod_rewrite Rule Modifiers

1) R Force external redirection
2) F disables the URL and returns a 403HTTP status code.
3 G force URL to gone, return 410HTTP status code.
4) P enforces the use of proxy forwarding.
5) L indicates that the current rule is the last rule, and the rewrite of the rule is stopped after parsing.
6) N rerun the rewrite process starting with the first rule.
7 C is associated with the next rule 8) T=mime-type (Force MIME type) force MIME type
9 NS only for not internal child requests
NC is case insensitive
One) QSA Append request string
NE does not output escape special characters \%3d$1 equivalent to =$1

using rewrite to implement Discuz pseudo static configuration under Apache virtual host

The first step: Of course is to configure Apache support rewrite function, this is not much said, is:
LoadModule Rewrite_module modules/mod_rewrite.so
Originally has the annotation to remove the annotation, originally did not add on.
In the configuration above:
1.Options FollowSymLinks This step of configuration must have.
2.AllowOverride all original none is to be changed to all.
These two configurations are indispensable.
The third step, we are more familiar with the more said,
is to add the. htaccess file under the corresponding directory, which is illustrated by the following Discuz example:
Rewriteengine on
Rewritebase/
Rewriterule ^archiver/((Fid|tid)-[\w\-]+\.html) $ archiver/index.php?$1
Rewriterule ^forum-([0-9]+)-([0-9]+) \.html$ forumdisplay.php?fid=$1&page=$2
Rewriterule ^thread-([0-9]+)-([0-9]+)-([0-9]+) \.html$ viewthread.php?tid=$1&extra=page\%3d$3&page=$2
Rewriterule ^space-(Username|uid)-(. +) \.html$ space.php?$1=$2
Rewriterule ^tag-(. +) \.html$ tag.php?name=$1

Fourth step: Configure Discuz to use pseudo static:
Login background management, into the "global" = "" Optimal Configuration "=" "Search Engine Optimization" in the original URL static location selected, and then submit.

The configuration is complete, go to discuz the front desk to be possible. The original PHP has become HTML.

set in the Apache configuration file
Copy Code code as follows:

<ifmodule mod_rewrite.c>
Rewriteengine on
Rewriterule ^ (. *)/archiver/((Fid|tid)-[\w\-]+\.html) $ $1/archiver/index.php?$2
Rewriterule ^ (. *)/forum-([0-9]+)-([0-9]+) \.html$ $1/forumdisplay.php?fid=$2&page=$3
Rewriterule ^ (. *)/thread-([0-9]+)-([0-9]+) – ([0-9]+) \.html$ $1/viewthread.php?tid=$2&extra=page\%3d$4& Page=$3
Rewriterule ^ (. *)/space-(USERNAME|UID)-(. +) \.html$ $1/space.php?$2=$3
Rewriterule ^/home/(Space|network)-(. +) \.html$/home/$1\.php\?rewrite=$2
Rewriterule ^/home/(space|network) \.html$/home/$1\.php
Rewriterule ^/home/([0-9]+) $/home/space\.php\?uid=$1
Rewriterule ^ (. *)/tag-(. +) \.html$ $1/tag.php?name=$2
</IfModule>

This article applies to Apache virtual host users.
Before you start with the following settings, you should first confirm that the server supports Mod_rewrite and support file resolution of the htaccess in the site directory, otherwise it is not available even if you set the following method. Click to see how to open mod_rewrite under Apache.
Apache under Open mod_rewrite
Server environment: Windows Server 2003 SP2 + Apache 2.0.59
Open method:
Open the Apache installation directory with a text editor \conf\httpd.conf, find the "#LoadModule rewrite_module modules/mod_rewrite.so" line, remove the front "#", and continue to find " AllowOverride None, modified to "allowoverride all", then restart Apache.

Verify that the. htaccess file exists in the directory in which the forum is located, and if it does not exist, create the file manually. Under the WIN32 system, you cannot directly create a. htaccess file, you can copy one from another system, or click here to download the one I do, unzip it to use. Edit and modify the. htaccess file and add the following:
Copy Code code as follows:

# Open the Rewriteengine mode
Rewriteengine on
# Modify the/discuz in the following statement for your forum directory address, if the program is placed in the root directory, please change/discuz to/
Rewritebase/discuz
# Rewrite System rules do not modify
Rewriterule ^archiver/([a-z0-9\-]+\.html) $ archiver/index.php?$1
Rewriterule ^forum-([0-9]+)-([0-9]+) \.html$ forumdisplay.php?fid=$1&page=$2
Rewriterule ^thread-([0-9]+)-([0-9]+)-([0-9]+) \.html$ viewthread.php?tid=$1&extra=page\%3d$3&page=$2
Rewriterule ^profile-(Username|uid)-(. +) \.html$ viewpro.php?$1=$2

When you add content, follow the instructions above, modify the path of the forum, and then save it. Upload the. htaccess file to the directory where the forum resides. Enter the forum system settings, as required to open the URL static function.

-=======================================================
Note that the following must be
Copy Code code as follows:

Namevirtualhost *:80
<virtualhost *:80>
ServerAdmin webmaster@domain.com
DocumentRoot "E:\aaa\wwwroot"
ServerName *
<ifmodule mod_rewrite.c>
Rewriteengine on
Rewriterule ^ (. *)/archiver/([a-z0-9-]+.html) $ $1/archiver/index.php?$2
Rewriterule ^ (. *)/forum-([0-9]+)-([0-9]+). html$ $1/forumdisplay.php?fid=$2&page=$3
Rewriterule ^ (. *)/thread-([0-9]+)-([0-9]+)-([0-9]+). html$ $1/viewthread.php?tid=$2&extra=page%3d$4&page= $
Rewriterule ^ (. *)/profile-(USERNAME|UID)-(. +). html$ $1/viewpro.php?$2=$3
Rewriterule ^ss-xs/([0-9]+)/spacelist (. *) $/index.php?$1/action_spacelist$2
Rewriterule ^ss-xs/([0-9]+)/viewspace_ (. +) $/index.php?$1/action_viewspace_itemid_$2
Rewriterule ^ss-xs/([0-9]+)/viewbbs_ (. +) $/index.php?$1/action_viewbbs_tid_$2
Rewriterule ^ss-xs/([0-9]+)/(. *) $/index.php?$1/$2
Rewriterule ^ss-xs/([0-9]+) $/index.php?$1
Rewriterule ^ss-xs/action_ (. +) $/index.php?action_$1
Rewriterule ^ss-xs/category_ (. +) $/index.php?action_category_catid_$1
Rewriterule ^ss-xs/itemlist_ (. +) $/index.php?action_itemlist_catid_$1
Rewriterule ^ss-xs/viewnews_ (. +) $/index.php?action_viewnews_itemid_$1
Rewriterule ^ss-xs/viewthread_ (. +) $/index.php?action_viewthread_tid_$1
Rewriterule ^ss-xs/index ([. a-za-z0-9]*) $/index.php
</IfModule>
</VirtualHost>

=======================
Copy Code code as follows:

Namevirtualhost 124.129.183.146
<virtualhost bbs.jb51.net>
ServerName bbs.jb51.net
DocumentRoot D:/website/phpbbs
<directory "D:/website/phpbbs" >
Options Indexes followsymlinks Includes
AllowOverride All
Order Allow,deny
Allow from all
</Directory>
DirectoryIndex index.php
<ifmodule mod_rewrite.c>
Rewriteengine on
Rewriterule ^ (. *)/archiver/([a-z0-9-]+.html) $ $1/archiver/index.php?$2
Rewriterule ^ (. *)/forum-([0-9]+)-([0-9]+). html$ $1/forumdisplay.php?fid=$2&page=$3
Rewriterule ^ (. *)/thread-([0-9]+)-([0-9]+)-([0-9]+). html$ $1/viewthread.php?tid=$2&extra=page%3d$4&page= $
Rewriterule ^ (. *)/profile-(USERNAME|UID)-(. +). html$ $1/viewpro.php?$2=$3
Rewriterule ^ss-xs/([0-9]+)/spacelist (. *) $/index.php?$1/action_spacelist$2
Rewriterule ^ss-xs/([0-9]+)/viewspace_ (. +) $/index.php?$1/action_viewspace_itemid_$2
Rewriterule ^ss-xs/([0-9]+)/viewbbs_ (. +) $/index.php?$1/action_viewbbs_tid_$2
Rewriterule ^ss-xs/([0-9]+)/(. *) $/index.php?$1/$2
Rewriterule ^ss-xs/([0-9]+) $/index.php?$1
Rewriterule ^ss-xs/action_ (. +) $/index.php?action_$1
Rewriterule ^ss-xs/category_ (. +) $/index.php?action_category_catid_$1
Rewriterule ^ss-xs/itemlist_ (. +) $/index.php?action_itemlist_catid_$1
Rewriterule ^ss-xs/viewnews_ (. +) $/index.php?action_viewnews_itemid_$1
Rewriterule ^ss-xs/viewthread_ (. +) $/index.php?action_viewthread_tid_$1
Rewriterule ^ss-xs/index ([. a-za-z0-9]*) $/index.php
</IfModule>
</VirtualHost>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.