简体   繁体   English

如何动态地编写.htaccess(即从查询字符串)

[英]How to write .htaccess dynamicaly (i.e from query string)

Bellow is my basic .htaccess code 波纹管是我的基本.htaccess代码

Options +FollowSymLinks
RewriteEngine on
RewriteBase /artist/
RewriteRule ^member/([^/]*)$ /artist/index.php?member=$1

Bellow is my static .htaccess code 波纹管是我的静态.htaccess代码

Options +FollowSymLinks
RewriteEngine on
RewriteBase /artist/
#we module doing some action
RewriteRule ^member/([^/]*)/([^/]*)/action/([^/]*)/$ /artist/index.php?member=$1&module=$2&action=$3
#action operation e.g create
RewriteRule ^member/([^/]*)/([^/]*)/action/([^/]*)/opt/([^/]*)/$ /artist/index.php?member=$1&module=$2&action=$3&opt=$4
#if only module calls
RewriteRule ^member/([^/]*)/([^/]*)/$ /artist/index.php?member=$1&module=$2
RewriteRule ^member/([^/]*)/([^/]*)/opt/([^/]*)/$ /artist/index.php?member=$1&module=$2&opt=$3
RewriteRule ^member/([^/]*)$ /artist/index.php?member=$1
RewriteRule ^member/0/$ /artist/index.php?member=$1
RewriteRule ^member/([^/]*)/([^/]*)/opt/([^/]*)/$ /artist/index.php?member=$1&module=$2&opt=$3  
RewriteRule ^member/([^/]*)/([^/]*)/opt/([^/]*)/topicId/([^/]*)/$ /artist/index.php?member=$1&module=$2&opt=$3&topicId=$4

can any one help me to write dynamic RewriteRule to add query sting in my RewiteRule so that i dont have to add manually RewriteRule and also it will reduce the line of my .htaccess code 有谁能帮助我编写动态RewriteRule来在RewiteRule中添加查询字符串,这样我就不必手动添加RewriteRule了,它还会减少我的.htaccess代码行

some thing like: 就像是:

RewriteRule ^member/([^/]*)[dynamic code]$ /artist/index.php?member=$1[dynamic code here]

At that point you rewrite all requests to /artist/index.php without constructing a query string, and index.php examines the request URI to populate its own variables. 那时,您将所有请求重写为/artist/index.php而没有构造查询字符串,并且index.php检查请求URI来填充其自己的变量。

ie have only one rule 即只有一条规则

RewriteRule ^member/.* /artist/index.php

index.php can look at $_SERVER['REQUEST_URI'] , explode on slashes, etc. index.php可以查看$_SERVER['REQUEST_URI'] ,在斜杠上explode等。

mod_rewrite's job is not to implement complex logic. mod_rewrite的工作不是实现复杂的逻辑。 You put it in your application. 您将其放在应用程序中。

http://en.wikipedia.org/wiki/Front_Controller_pattern http://en.wikipedia.org/wiki/Front_Controller_pattern

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM