Sei sulla pagina 1di 10

mod-rewrite

#mod-
rewrite
1

1: mod-rewrite 2

Examples 2

Debian / Ubuntu 2

mod_rewrite 2

mod_rewrite 2

2: Apache 2.4mod-rewrite 4

Examples 4

Apache 2.4 4

RewriteBaseRewriteEngine 5

RewriteBase 5

RewriteEngine 5

RewriteMap 5

3: 6

Examples 6

PHP 6

urlphp 6

4: 7

Examples 7

8
You can share this PDF with anyone you feel could benefit from it, downloaded the latest version
from: mod-rewrite

It is an unofficial and free mod-rewrite ebook created for educational purposes. All the content is
extracted from Stack Overflow Documentation, which is written by many hardworking individuals at
Stack Overflow. It is neither affiliated with Stack Overflow nor official mod-rewrite.

The content is released under Creative Commons BY-SA, and the list of contributors to each
chapter are provided in the credits section at the end of this book. Images may be copyright of
their respective owners unless otherwise specified. All trademarks and registered trademarks are
the property of their respective company owners.

Use the content presented in this book at your own risk; it is not guaranteed to be correct nor
accurate, please send your feedback and corrections to info@zzzprojects.com

https://riptutorial.com/zh-TW/home 1
1: mod-rewrite
mod_rewriteApache。URL。

mod_rewritemod_alias。 mod_rewrite mod_authz_coremod_authz_host。 mod_rewrite


mod_proxyProxyPassProxyPassMatch 。

mod_rewrite.htaccess。httpd.conf。

2.2 2015717

2.4 201675

Examples
Apachemod_rewrite。

Debian / Ubuntu
a2enmod rewrite

service apache2 restartApache

httpd.conf

LoadModule rewrite_module modules/mod_rewrite.so

Apache。

mod_rewrite

mod_rewriteRewriteRuleRewriteCondRewriteBaseRewriteMap 。

RewriteEngine on

。mod_rewrite。。

mod_rewrite

.htaccess。httpd.conf。

AllowOverride“Fileinfo”。

AllowOverride FileInfo

https://riptutorial.com/zh-TW/home 2
AccessFileName。.htaccess。

mod_rewrite

RewriteEngine on

mod-rewrite https://riptutorial.com/zh-TW/mod-rewrite/topic/5687/mod-rewrite

https://riptutorial.com/zh-TW/home 3
2: Apache 2.4mod-rewrite
• RewriteBase URL-path
• RewriteCond TestString CondPattern
• RewriteEngine on | off
• RewriteMap MapName MapTypeMapSource
• RewriteOptions
• []

Examples
Apache 2.4

Apache 2.4mod_rewrite6

1. RewriteBase
2. RewriteCond
3. RewriteEngine
4. RewriteMap
5. RewriteOptions
6.

Apache 2.2

1. RewriteLock
2. RewriteLog
3. RewriteLogLevel

mod_rewrite RewriteMapAllowOverride FileInfo.htaccess 。

RewriteBase .htaccess URL

RewriteCond

RewriteEngine

RewriteMap

RewriteOptions

Everwhere

1.
2.
3.
4. .htaccess

https://riptutorial.com/zh-TW/home 4
RewriteLogRewriteLogLevelLogLevel

LogLevel rewrite:<level>

<level>trace8 emerg 。。

RewriteBaseRewriteEngine

RewriteBase .htaccess URL

RewriteEngine

RewriteBase

URL。

RewriteEngine

off 。。

RewriteMap

RewriteMap

RewriteMap MAPNAME Type:Source

RewriteCondRewriteRule

${ MAPNAME : KEY | DEFAULT }

Type

1. int - toupper tolower escapeunescape


2. txt -
3. dbd - SQL SELECT
4. rnd -
5. dbm - txt httxt2dbm
6. fastdbd - SQL SELECT

Apache 2.4mod-rewrite https://riptutorial.com/zh-TW/mod-rewrite/topic/5981/apache-2-4mod-


rewrite

https://riptutorial.com/zh-TW/home 5
3:
Examples
PHP

http://example.com/topic/id-seonameurlidphp。“” 。

RewriteEngine on

RewriteRule ^topic/([0-9]+)-[^/]*/?$ /topics.php?id=$1 [L]

topic/。。seo。 mod_rewriteseoseo。 RewriteRuleurl。$1。([0-9]+) 。

urlphp

RewriteRule 。RewriteCond。URLURL。

RewriteCond %{QUERY_STRING} ^name=([^&]*)$


RewriteRule ^oldscript\.php$ newscript.php?username=%1 [L]

。 %1。([^&]*)。

https://riptutorial.com/zh-TW/mod-rewrite/topic/6162/

https://riptutorial.com/zh-TW/home 6
4:
RewriteRule。RewriteEngine on。

Examples
<Directory></Directory>。.htaccess。

RewriteRuleurl。

http://example.com/foo?id=1 RewriteRulefoo。 http example.com / 。 ?id=1 。

<Directory "/">
RewriteRule ^foo$ bar [L]
</Directory>

url http://example.com/topic/15-my-topic-name RewriteRuletopic/15-my-topic-name

<Directory "/topic/">
RewriteRule ^topic/([0-9]+)-[^/]*/?$ topics.php?id=$1 [L]
</Directory>

www-root.htaccessURL http://example.com/foo?id=1 foo。

RewriteRule ^foo$ bar [L]

URL /。RewriteRule ^/。

<VirtualHost></VirtualHost>。

RewriteRuleurl。

URL http://example.com/foo?id=1 RewriteRule/foo。

<VirtualHost 1.2.3.4:80>
ServerName example.com

RewriteEngine on
RewriteRule ^/foo$ /bar [L]
</VirtualHost>

https://riptutorial.com/zh-TW/mod-rewrite/topic/6065/

https://riptutorial.com/zh-TW/home 7
S.
Contributors
No

1 mod-rewrite 4444, Community, Sumurai8

Apache 2.4mod-
2 hjpotter92
rewrite

3 Sumurai8

4 Sumurai8

https://riptutorial.com/zh-TW/home 8

Potrebbero piacerti anche