Forum Moderators: phranque

Message Too Old, No Replies

Mass redirection with dynamic Variables (.htaccess)

         

omoutop

10:35 am on Aug 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi to all!
Need ur wisdom guys....

a simple redirection in .htaccess is syntaxed like this:
RedirectPermanent /domain1/domain11/index.htm [domain.com...]

BUT what if I have numerous domains and for a specific set of links I need to redirect users?

i.e.
RedirectPermanent /domain1/domain11/hotel/index.htm [domain.com...]

domain1 and domain11 are not static but dynamic...I need a rule to work for domain1, 2, 3, 4, 5 and domain11,2,33,44

something like this

RedirectPermanent /*/*/hotel/index.htm [domain.com...]

Any Ideas?
thx in advanceeeee

jdMorgan

8:07 pm on Aug 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



See the Apache RedirectMatch [httpd.apache.org] directive. You can use regular expressions to match the variables, and then back-reference them to create the new URLs.

Jim

omoutop

12:30 pm on Aug 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thx for the link jdMorgan...
I tried RedirectMatch and it works fine...however...

RedirectMatch /(.*)-hotel.htm$ /$1-hotels-alpha-.htm

the second part (link/page) "/$1-hotels-alpha-.htm" is also created by a previous rule in order to transform from php to htm and the problem is that intead of getting this url (once redirected):
/ios-hotels-alpha-.htm
i get this:
/ios-hotels-alpha-.htm?area_name=cyclades&island_name=ios&island_name=ios&type_name=hotel

which includes the php variables

my transformation rule is:

RewriteRule ^(.*)/(.*)/hotels/(.*)-(.*)-alpha-(.*).htm$ list_alphabetical.php?area_name=$1&island_name=$2&island_name=$3&type_name=$4&alph=$5 [nc]

and works fine...
ANY IDEAS?
thx in advance...

jdMorgan

11:01 pm on Aug 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'll need to use mod_rewrite to clear the query string, which is probably a good idea anyway, since you are using it for the other redirect.

RewriteRule ^([^-]+)-hotel\.htm$ /$1-hotels-alpha-.htm?
RewriteRule ^([^/]+)/([^/]+)/hotels/([^-]+)-([^-]+)-alpha-([^.]+)\.htm$ list_alphabetical.php?area_name=$1&island_name=$2&island_name=$3&type_name=$4&alph=$5 [NC]

The forward-looking negative-match patterns shown should speed up processing considerably, as long as your URLs don't contain hyphens or slashes which are not used as parameter separators. You should also try adding an [L] flag to each rule unless you know that the output of the first rule needs to be modified by the second rule as well (I'm not sure, because I don't know how your site is set up).

Jim

omoutop

8:42 am on Aug 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thx again for everything Jim,
really appreciated the help and tips...

I have created this by combining ur thoughts:

RewriteRule ^(.*)-hotel(.*).htm$ $1-hotels-alpha-$2.htm?

RewriteRule ^(.*)/(.*)/hotels/(.*)-(.*)-alpha-(.*).htm$ list_alphabetical.php?area_name=$1&island_name=$2&island_name=$3&type_name=$4&alph=$5 [nc]

which is working fine...for instance...

the url "cyclades/ios/hotels/ios-hotel.htm" calls succesfully the "cyclades/ios/hotels/ios-hotels-alpha-.htm"...

But...
I when using the additional string to display the hotels by names...(scripts are running...ulz are still a problem)...for instance:

the url "cyclades/ios/hotels/ios-hotelA.htm" which should call "cyclades/ios/hotels/ios-hotels-alpha-A.htm"
calls the "cyclades/ios/hotels/ios-hotels-alpha-.htm" which is actually the first page...The A,B,C...etc do not pass to the "&alph=$5 " and the script is not working correctly...

This is the last bit.....I would like to call:
"cyclades/ios/hotels/ios-hotelA.htm"
"cyclades/ios/hotels/ios-hotelB.htm"
"cyclades/ios/hotels/ios-hotelC.htm" etc. and get the

"cyclades/ios/hotels/ios-hotels-alpha-A.htm"
"cyclades/ios/hotels/ios-hotels-alpha-B.htm"
"cyclades/ios/hotels/ios-hotels-alpha-C.htm"

I tried this in my rule above
RewriteRule ^(.*)-hotel(.*).htm$ $1-hotels-alpha-$2.htm?

RewriteRule ^(.*)/(.*)/hotels/(.*)-(.*)-alpha-(.*).htm$ list_alphabetical.php?area_name=$1&island_name=$2&island_name=$3&type_name=$4&alph=$5 [nc]
but it is not working......

I need ur wisdom...
Thx for everything again..

omoutop

jdMorgan

2:46 pm on Aug 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You are using (.*) patterns, which are inefficient and ambiguous, and can lead to unexpected results. I strongly suggest you re-read my post above about using more-specific patterns.

Also, flush your browser cache before testing *any* change to your code.

Jim