Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule for root and sub folder to new sub folder

Regex help needed

         

SamTeeeee

6:06 pm on Feb 7, 2011 (gmt 0)

10+ Year Member



Hi, I need a little help with the Regex for my Rewrite rule please.

I want to redirect all requests for the root and for a folder called "cfd" to a folder called "touch", and retain the name of the page that is being requested. All based on a RewriteCond.

Here is what i have so far:

RewriteCond %{HTTP:X-DeviceAtlas-touchScreen} 1
RewriteCond %{HTTP:X-DeviceAtlas-displayWidth} <500
RewriteRule ^(\/|\/cfd\/(.*))$ /touch/$1 [L,R=302]

This however does not work and the rewrite/redirect doesnt happen.

Any pointers?

Thanks
Sam

BreathinBuddah

6:27 am on Mar 6, 2011 (gmt 0)

10+ Year Member



^/?cfd/(.*)$ /touch/$1 


basically: "there might be a slash, if there is omit it (lazy), grab everything after the cfd directory" and "add the captured url to the end of the /touch/ directory"

untested, but it feels right

note: this board removes multiple question marks for spam reason i guess (very dumb) but there should be two after the initial slash.

g1smd

11:21 am on Mar 6, 2011 (gmt 0)

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



Almost the exact same question over here: [webmasterworld.com...]

The code will need minimal changes to fit your situation.

jdMorgan

5:52 pm on Mar 9, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you're looking to match a value of "1" in the first header check, and NOT match any value containing a "1" such as "11" or "321", then:

RewriteCond %{HTTP:X-DeviceAtlas-touchScreen} =1
RewriteCond %{HTTP:X-DeviceAtlas-displayWidth} <500
RewriteRule ^(cfd/(.*))?$ http://www.example.com/touch/$2 [R=302,L]

Jim