Rewrite static server configuration method under Apache and IIS in PHP

Source: Internet
Author: User

iscuz! URL static functionality by the Forum Server environment constraints, before you turn on this feature, according to your WEB server environment, select the appropriate environment configuration method. Incorrect settings may cause the server to fail to start or not function.
One, Apache Web Server (standalone host user)
first determines the version of Apache that you are using, and whether the Mod_rewrite module is loaded.
Apache 1.x users check the conf/httpd.conf for the following two-paragraph code:
   LoadModule rewrite_module     libexec/mod_rewrite.so
   addmodule mod_rewrite.c
Apache 2.x users check to see if the following code exists in conf/httpd.conf:
   LoadModule rewrite_module     modules/mod_rewrite.so
If present, then in the configuration file (usually conf/ httpd.conf), add the following code. It is important to note that if the site is defined by a virtual host, it must be added to the virtual host configuration, that is, <VirtualHost>, if added outside the virtual host configuration will probably not be available. After the change, the Apache will be restarted.

  code is as follows copy code
<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 ^ (. *)/tag-(. +). html$ $1/tag.php?name=$2
</ifmodule>


If you do not have Mod_rewrite installed, you can recompile Apache and add –enable-rewrite=shared to the contents of the original configure, and then add the above code to the Apache configuration file.
Two, Apache Web Server (Virtual host user)
before starting the following settings, first consult your space service provider, whether space supports Rewrite, and whether to support file resolution in the Site Directory. htaccess. Otherwise, you cannot use it even if you set it up in the following way.
Check to see if the. htaccess file exists in the directory in which the forum resides, and if it does not exist, create the file manually. Win32 system, you cannot directly create a. htaccess file, you can copy a copy from another system, or download the file in the Discuz.net Technical Support Section. Edit and modify the. htaccess file, add the following
# Open 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 Discuz modified to/
Rewritebase/discuz
# Rewrite System rules do not modify

  code is as follows copy code
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

When you add content to the


, follow the prompts above, modify the path where the forum is located, and then save. Upload the. htaccess file to the directory where the forum resides. Then enter the forum system set up search engine optimization, as required to open the URL static function.
Third, IIS Web Server (standalone host user)
first adds this filter on the IIS Isapi, the filter name is Rewrite, the executable file selects Rewrite.dll, and the IIS restarts. The Httpd.ini is already set up in the attachment, which reads as follows:

  code is as follows copy code
[isapi_rewrite"
# 3600 = 1 hour
Cacheclockrate 3600
Repeatlimit
# Protect Httpd.ini and Httpd.parse.errors files
# from accessing through HTTP
Rewriterule ^ (. *)/archiver/((Fid|tid )-[w-]+.html)? * (. *) $ $1/archiver/index.php?$2&$4
Rewriterule ^ (. *)/forum-([0-9]+)-([0-9]+). html?* (. *) $ $1/ forumdisplay.php?fid=$2&page=$3&$4
Rewriterule ^ (. *)/thread-([0-9]+)-([0-9]+)-([0-9]+). html?* (. *) $ $ /viewthread.php?tid=$2&extra=page%3d$4&page=$3&$4
Rewriterule ^ (. *)/space-(USERNAME|UID)-(. +). html?* (. *) $ $1/space.php?$2=$3&$4
Rewriterule ^ (. *)/tag-(. +). html?* (. *) $ $1/tag.php?name=$2&$3

Then enter the forum system set up search engine optimization, as needed to open the URL static function.
Attachment Download Address:

Four, Zeus Web Server
Locate the Request rewriting in the virtual host configuration, write the following in the Rewrite Script, and then Apply changes and make it take effect.

The code is as follows Copy Code
Match URL into $ with ^ (. *)/archiver/((Fid|tid)-[w-]+.html)? * (. *) $
If matched then
Set URL = $1/archiver/index.php?$2&$4
endif
Match URL into $ with ^ (. *)/forum-([0-9]+)-([0-9]+). html?* (. *) $
If matched then
Set URL = $1/forumdisplay.php?fid=$2&page=$3&$4
endif
Match URL into $ with ^ (. *)/thread-([0-9]+)-([0-9]+)-([0-9]+). html?* (. *) $
If matched then
Set URL = $1/viewthread.php?tid=$2&extra=page%3d$4&page=$3&$4
endif
Match URL into $ with ^ (. *)/space-(USERNAME|UID)-(. +?). html?* (. *) $
If matched then
Set URL = $1/space.php?$2=$3&$4
endif
Match URL into $ with ^ (. *)/tag-(. +?). html?* (. *) $
If matched then
Set URL = $1/tag.php?name=$2$3
endif

===========================================================
IIS Web Server (standalone host user) 1, download IIS rewrite module: http://www.isapirewrite.com/download/isapi_rwl_x86_0059.msi;

2, extract the compressed package to any directory, (such as: C:rewrite). Then open the Control Panel-Administrative Tools-IIS Information Services Manager-Web site-Your site-Properties. " In the ISAPI filter entry, click Add, the filter name is filled in rewrite, and the executable file is C:rewriterewrite.dll;
3, and then modify the Httpd.ini file, add the appropriate filtering rules, such as:

The code is as follows Copy Code
Rewriterule ^ (. *)/([a-z0-9-_]+) $ $1/default.aspx?id=$2 [I,o]
Http://localhost/Text will be equated to http://localhost/Default.aspx?id=Text.
Rewriterule ^ (. *)/id_ ([a-z0-9-]+). html$ $1/default.aspx?id=$2 [I,o]
Http://localhost/id_Text.html will be equated to http://localhost/Default.aspx?id=Text.
^ (. *)/html/([0-9]+)/([0-9]+). html$ $1/default.aspx?id=$2&name=$3
Http://localhost/html/001/007.html is equivalent to http://localhost/Default.aspx?id=001&name=007.


4. Restarting IIS can take effect (this step is important to restart IIS to load the configuration every time you modify Httpd.ini.) )

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.