Forum Moderators: phranque
What I am trying to do:
My website has a number of templates (or styles) set up and one of them, 'styleid=7', is specifically for PDAs.
In my current root directory .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} "Windows CE" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Blackberry" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "NetFront" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Palm OS" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Blazer" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Elaine" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "^WAP.*$" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Plucker" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "AvantGo" [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*) /forums/$1?styleid=7 [L,R]
This should work by redirecting any PDA request to any file in the root directory only through immediately to the 'forums/' directory and add '?styleid=7'. (At least thats what I think it does - it works anyhow)
What I am now needing:
I now want to be able to check any filerequests in the /forums/ directory and sub directories and check if the 'styleid=7' rule needs to be applied.
What I have tried to code:
RewriteCond %{HTTP_USER_AGENT} "Windows CE" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Blackberry" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "NetFront" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Palm OS" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Blazer" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Elaine" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "^WAP.*$" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Plucker" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "AvantGo" [NC]
RewriteCond %{QUERY_STRING} "!.gif"=[NC]
RewriteCond %{QUERY_STRING} "!vbseo.php" [NC]
RewriteCond %{QUERY_STRING} "!vbseo_getsitemap.php" [NC]
RewriteCond %{QUERY_STRING} "!styleid=7" [NC]
RewriteRule ^(.*)$ $1?styleid=7 [L,R]
I have tried this in the .htaccess in my forums directory but its not working. I have messed about a load and occasionally I would get a 'close hit' where the code did something but not exactly what I needed. More often than not I ended up in a recursive loop.
Can someone help me to achieve what I need overall, namely:
1. Check if browser accessing root folder is PDA and if so, redirect immediately to forums/index.php?styleid=7
2. Check if any files being requested from the forums directory by PDA and sub directory have anything other than styleid=7 applied and if so, delete other style and apply the styleid=7 instead.
Hope this makes sense!
Oh, also, I need to exclude a number of filetypes (eg .gif images, vbseo.php)
An example of how my site URLs end is forums/frequently-asked-questions-faqs/35586-thread-viewing-options.html#post428050
(Admins, please note his is not a full URL, just an example of how my URLs are constructed)
Thanks in advance
Thanks very much.
__________________
Regards
Jay
Welcome to WebmasterWorld!
This isn't so much a question as a project! I'll try to point you in the right direction:
There's no need to use an external redirect. I suggest a server-internal rewrite only:
RewriteRule ^(.*)$ $1?styleid=7 [b][L][/b]
More often than not I ended up in a recursive loop.
You need to explicitly prevent this loop in your second code section, just as you did in the first section. Use
RewriteCond %{QUERY_STRING} !styleid=7[^0-9]*
Can someone help me to achieve what I need overall, namely:1. Check if browser accessing root folder is PDA and if so, redirect immediately to forums/index.php?styleid=7
You've done that in the first code section, I think.
2. Check if any files being requested from the forums directory by PDA and sub directory have anything other than styleid=7 applied and if so, delete other style and apply the styleid=7 instead.
# Case: Name/value pair precedes styleid
RewriteCond %{QUERY_STRING} !styleid=7[^0-9]*
RewriteCond %{QUERY_STRING} ^(.+)&styleid=[0-9]+(.*)$
RewriteRule ^(forums/.*) /$1?%1&styleid=7%2 [L]
#
# Case: No name/value pair precedes styleid
RewriteCond %{QUERY_STRING}!styleid=7[^0-9]*
RewriteCond %{QUERY_STRING} ^styleid=[0-9]+(.*)$
RewriteRule ^(forums/.*) /$1?styleid=7%1 [L]
Oh, also, I need to exclude a number of filetypes (eg .gif images, vbseo.php)
RewriteCond %{REQUEST_URI} !\.(gif¦php)$
For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].
Jim
Thanks again for the help - I feel I'm getting closer but its still voodoo :)
RewriteEngine On
#
RewriteCond %{HTTP_USER_AGENT} "Windows CE" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Blackberry" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "NetFront" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Palm OS" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Blazer" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Elaine" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "^WAP.*$" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Plucker" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "AvantGo" [NC]
RewriteCond %{REQUEST_URI}!\.(gif¦php)$
RewriteRule ^(.*)$ $1?styleid=7 [L]
#
RewriteCond %{HTTP_USER_AGENT} "Windows CE" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Blackberry" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "NetFront" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Palm OS" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Blazer" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Elaine" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "^WAP.*$" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Plucker" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "AvantGo" [NC]
RewriteCond %{REQUEST_URI}!\.(gif¦php)$
RewriteCond %{QUERY_STRING}!styleid=7[^0-9]*
RewriteCond %{QUERY_STRING} ^(.+)&styleid=[0-9]+(.*)$
RewriteRule ^(forums/.*) /$1?%1&styleid=7%2 [L]
#
RewriteCond %{HTTP_USER_AGENT} "Windows CE" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Blackberry" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "NetFront" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Palm OS" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Blazer" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Elaine" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "^WAP.*$" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Plucker" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "AvantGo" [NC]
RewriteCond %{REQUEST_URI}!\.(gif¦php)$
RewriteCond %{QUERY_STRING}!styleid=7[^0-9]*
RewriteCond %{QUERY_STRING} ^styleid=[0-9]+(.*)$
RewriteRule ^(forums/.*) /$1?styleid=7%1 [L]
RewriteEngine on
#
# If mobile device UA or gif or PHP file
RewriteCond %{HTTP_USER_AGENT} !(Windows\ CE¦Blackberry¦NetFront¦Palm\ OS¦Blazer¦Elaine¦^WAP¦Plucker¦AvantGo) [NC,OR]
RewriteCond %{REQUEST_URI} \.(gif¦php)$
# skip next three rules
RewriteRule .* - [S=3]
#
# Rewrite mobile client requests for root directory only to forums subdirectory
RewriteRule ^([^/]*)$ /forums/?styleid=7 [L]
#
# Force style id 7 for mobile clients, case one
RewriteCond %{QUERY_STRING} !styleid=7[^0-9]*
RewriteCond %{QUERY_STRING} ^(.+)&styleid=[0-9]+(.*)$
RewriteRule ^(forums/.*) /$1?%1&styleid=7%2 [L]
#
# Force style id 7 for mobile clients, case two
RewriteCond %{QUERY_STRING} !styleid=7[^0-9]*
RewriteCond %{QUERY_STRING} ^styleid=[0-9]+(.*)$
RewriteRule ^(forums/.*) /$1?styleid=7%1 [L]
#
# Skip directive in the first rule lands here. Place additional rules
# (if any) for .gif files, .php files, and non-mobile user-agents here.
#
Jim