mod rewrite

  • saybrah
  • Student
  • Student
  • saybrah
  • Posts: 69

Post 3+ Months Ago

ok i have an issue...

my regular link is http://www.domain.com/folder?aff=123

thats not a problem using
APACHE Code: [ Select ]
RewriteRule ^(.*)/([0-9]+)$ /folder/?aff=$2 [R=301,L]


which works for http://www.domain.com/folder/Name/123

here's my issue
i need to check if an extra variable is set > http://www.domain.com/folder/?aff=123&extra

how do i go about that? so i can use http://www.domain.com/folder/Name/123/extra
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • saybrah
  • Student
  • Student
  • saybrah
  • Posts: 69

Post 3+ Months Ago

nevermind i figured it out :) suprise it was so simple but yet this post didnt receive any replies.
  • BIOSTALL
  • Graduate
  • Graduate
  • User avatar
  • Posts: 125
  • Loc: UK

Post 3+ Months Ago

saybrah, do you mind if I ask how you achieved this? I am currently doing a lot of .htaccess work and this would be handy to know...

Thanks :)
  • miker
  • Newbie
  • Newbie
  • miker
  • Posts: 7

Post 3+ Months Ago

I usually set these up like so:

APACHE Code: [ Select ]
RewriteRule folder/(.*)/ path_to_file.php?aff=$1


So for 2 variables:

APACHE Code: [ Select ]
RewriteRule folder/(.*)/(.*)/ path_to_file.php?aff=$1&extra=$2


if you want to allow it to be accessinble without the trailing slash then add that rule after above like so:

APACHE Code: [ Select ]
RewriteRule folder/(.*)/(.*)/ path_to_file.php?aff=$1&extra=$2
RewriteRule folder/(.*)/(.*) path_to_file.php?aff=$1&extra=$2
  1. RewriteRule folder/(.*)/(.*)/ path_to_file.php?aff=$1&extra=$2
  2. RewriteRule folder/(.*)/(.*) path_to_file.php?aff=$1&extra=$2


if you are using an undefined number of extra variables you can pass them together like so

folder/123/dino/news/

- the folder/123/ part is obvious and then you have a remainder that will all belong to the variable extra - this part:

dino/news/

you can use this method for passing multiples that are unfined rules by setting up your page to access that portion using the REQUEST_URI and splitting it into an array like so:

PHP Code: [ Select ]
$attributes = explode("/", $_REQUEST[extra]);
 
$attributes[0] = dino
$attributes[1] = news
  1. $attributes = explode("/", $_REQUEST[extra]);
  2.  
  3. $attributes[0] = dino
  4. $attributes[1] = news


I had to use this method for creating Rules for dynamic subdomains using Wildcard DNS.

May come in handy for those of you developing larger applications using dynamic subdomains.

There is a big difference from creating a social networking site that creates dynamic urls like:

domain.com/member/miker/

to a url like:

miker.domain.com

in which case .htaccess only goes so far and it is time to bring out the URI.

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 64 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.