Static server configuration of Rewrite under apache and iis in PHP

Source: Internet
Author: User

This article uses Discuz! URL static describes the static rules of apache and iis servers in php. If you need them, refer to this article.

Iscuz! The URL static function is restricted by the server environment where the forum is located. Before enabling this function, select the appropriate environment configuration method based on your Web server environment. Incorrect settings may cause the server to fail to start or the function to be invalid.
I. Apache Web Server (independent host user)
First, determine the Apache version you are using and whether the mod_rewrite module is loaded.
For Apache 1.x users, check whether the following two sections of code exist in conf/httpd. conf:
LoadModule rewrite_module libexec/mod_rewrite.so
AddModule mod_rewrite.c
For Apache 2.x users, check whether the following code exists in conf/httpd. conf:
LoadModule rewrite_module modules/mod_rewrite.so
If yes, add the following code to the configuration file (usually conf/httpd. conf. Note that if the website is defined by a virtual host, you must add it to the virtual host configuration, that is, <VirtualHost>. If it is added to the virtual host configuration, it may not be available. Restart Apache after modification.

The Code is as follows: Copy code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^ (. *)/archiver/(fid | tid0000-0000w-00000000.html) $1/archiver/index. php? $2
RewriteRule ^ (. *)/forum-(%0-9%%*-(%0-9%%%%%%%.html $1/forumdisplay. php? Fid = $2 & page = $3
RewriteRule ^ (. *)/thread-(0-9000000000000-(0-9000000000000-(0-90000000000000000.html $1/viewthread. php? Tid = $2 & extra = page % 3D $4 & page = $3
RewriteRule ^ (. *)/space-(username | uid0000-(.20.0000.html $1/space. php? $2 = $3
RewriteRule ^ (. *)/tag-(.20.0000.html $1/tag. php? Name = $2
</IfModule>


If mod_rewrite is not installed, You Can recompile Apache, add-enable-rewrite = shared to the configure content, and then add the above Code to the Apache configuration file.
Ii. Apache Web Server (Virtual Host user)
Before proceeding with the following settings, please first consult your space service provider, whether the space supports Rewrite and whether it supports the site directory. file Parsing of htaccess, otherwise it cannot be used even if it is set according to the following method.
Check whether the. htaccess file exists in the directory where the forum is located. If not, create this file manually. A. htaccess file cannot be directly created in Win32. You can copy the file from another system or download the file in the Discuz.net technical support topic. Edit and modify the. htaccess file and add the following content:
# Enable RewriteEngine Mode
RewriteEngine On
# Modify/discuz in the following statement to your forum directory address. If your program is in the root directory, change/discuz/
RewriteBase/discuz
# Do not modify Rewrite system rules

The Code is as follows: Copy code
RewriteRule ^ archiver/(fid | tid0000-0000w-00000000.html) $ archiver/index. php? $1
RewriteRule used forum-(%0-9%%%%%-(%0-9%%%%%%.html $ forumdisplay. php? Fid = $1 & page = $2
RewriteRule implements thread-(%0-9%%%%%-(%0-9%%%%%%%%%%%%.html $ viewthread. php? Tid = $1 & extra = page % 3D $3 & page = $2
RewriteRule ^ space-(username | uid316-(.20.0000.html $ space. php? $1 = $2
RewriteRule implements tag-(.20.20..html $ tag. php? Name = $1


When adding content, follow the prompts above to modify the path of the forum and save it. Upload the. htaccess file to the directory where the forum is located. Then, go to the search engine optimization page of the forum system and enable the URL static function as needed.
Iii. IIS Web Server (independent host user)
First, add this filter on IIS Isapi. The filter name is Rewrite. Select Rewrite. dll as the executable file and restart IIS. Httpd. ini has been set in the attachment. The content is as follows:

The Code is as follows: Copy code
[ISAPI_Rewrite]
#3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
# Protect httpd. ini and httpd. parse. errors files
# From accessing through HTTP
RewriteRule ^ (. *)/archiver/(fid | tid0000-0000w-00000000.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? * (. *) $1/viewthread. php? Tid = $2 & extra = page % 3D $4 & page = $3 & $4
RewriteRule ^ (. *)/space-(username | uid0000-(.20.0000.html? * (. *) $1/space. php? $2 = $3 & $4
RewriteRule ^ (. *)/tag-(.20.20..html? * (. *) $1/tag. php? Name = $2 & $3

Then go to the search engine optimization set in the forum system and enable URL static function as needed.
Attachment:
 
Iv. Zeus Web Server
Find Request Rewriting in VM configuration, write the following content in Rewrite Script, then Apply changes and make it take effect.
 

The Code is as follows: Copy code
Match URL into $ with ^ (. *)/archiver/(fid | tid0000-0000w-00000000.html )? * (. *) $
If matched then
Set URL = $1/archiver/index. php? $2 & $4
Endif
Match URL into $ with ^ (. *)/forum-(%0-9000000000000-(%0-9000000000000.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 (independent host user) 1. Download IIS Rewrite module: http://www.isapirewrite.com/download/isapi_rwl_x86_0059.msi;
 
2. decompress the compressed package to any directory (for example, C: Rewrite ). Choose "Control Panel"> "Administrative Tools"> "IIS Information Service Manager"> "website"> "your site"> "properties ". Click "add" in the "ISAPI filter" item, and enter the Filter Name in Rewrite. the executable file is C: RewriteRewrite. dll;
3. Modify the httpd. ini file and add the corresponding filter rules, for example:

The Code is as follows: Copy code
RewriteRule ^ (. *)/([a-z0-9-_] +) $1/Default. aspx? Id = $2 [I, O]
Http: // localhost/Text is equivalent 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 is equivalent 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. Restart IIS to take effect. (This step is very important. Restart IIS to load the configuration every time httpd. ini is modified .)

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.