Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite - dynamic redir to static

         

papamaku

10:24 pm on Dec 7, 2003 (gmt 0)

10+ Year Member



hi all

have spent the whole of today learning about the wonders of mod_rewriting.

have almost solved what i needed to do, but there is still one slight bug.

i need to take a url such as:

www.domain.com/lookup?url=www.submittedurl.com

and in the browser address bar, have it chage to:

www.domain.com/www.submittedurl.com/display.html

so far i have this:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^url\=(.*)$
RewriteRule ^/lookup$ /%1/display.html [R]

and what it gives me is:

www.domain.com/www.submittedurl.com/display.html?url=www.submittedurl.com

any idea of how to get rid of the final '?url=www.submittedurl.com'

many thanks

jdMorgan

10:31 pm on Dec 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Adding a question mark to the end of your substitution URL will clear the old query string. The question mark itself will not show in the new URL.

RewriteRule ^/lookup$ /%1/display.html? [R]

Jim

papamaku

10:49 pm on Dec 7, 2003 (gmt 0)

10+ Year Member



excellent, that did it.

many many thanks

papamaku

3:14 pm on Dec 8, 2003 (gmt 0)

10+ Year Member



Hi guys, one other thing,

if i wanted the url to look like:

www.domain.com/www-submittedurl-com.html

i.e. swap the '.' for '-'

what do i need to modify in my rewrite rules:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^url\=(.*)$
RewriteRule ^/lookup$ /%1.html? [R]

jdMorgan

8:06 pm on Dec 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^url=([^.])\.([^.])\.(.*)$
RewriteRule ^/lookup$ /%1-%2-%3.html? [R]

Ref: [etext.lib.virginia.edu...]

Jim

papamaku

11:16 pm on Dec 8, 2003 (gmt 0)

10+ Year Member



cheers jim

i see, so you split the url into the 3 variables around the '.' then put them together around the '-'

but what if the domain is a .co.uk or has many subdomains?

is there a way of doing a 'search & replace' through the querystring, replacing all the '.' with '-'

thanks for all the help

killroy

11:20 pm on Dec 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Unfortunately there is not. The common solution in a case like this were there are only a small number of possibilities...

In other words, write 3 or 4 rules, covering cases with one (domain.com), two, three or four dots.

SN