shreyang
shreyang

Reputation: 1

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

Bellow is my basic .htaccess code

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

Bellow is my static .htaccess code

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

some thing like:

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

Upvotes: 0

Views: 199

Answers (1)

Dan Grossman
Dan Grossman

Reputation: 52382

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.

i.e. have only one rule

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

index.php can look at $_SERVER['REQUEST_URI'], explode on slashes, etc.

mod_rewrite's job is not to implement complex logic. You put it in your application.

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

Upvotes: 1

Related Questions