Notice to IE and other, excluding Firefox

New to mod_rewrite? This is a good place to start.

Notice to IE and other, excluding Firefox

Postby huyhoa » Sun May 31, 2009 6:52 pm

Hi!
I have a problem and wondering if some one could help me (especial richard :P ).
I have a forum at http://mysite.com/forum and all visit much visit it throught http://mysite.com (all non referrer or not mysite.com referrer will move to mysite.com then after click to link on mysite.com to go to mysite.com/forum)
I have this code to do it.

Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com(/.*)?$ [NC]
RewriteRule \.(txt|zip|pdf|exe|rar|pps|avi|wmv|mpg|html|php|asp|jsp|htm|gif|png|jpg)$ /index.php [NC,L]


So, now i want, when user use firefox, it work (i mean do it as it will be), but when user use other browser like IE, opera.... (all other) it will move to a notice site (like mysite.com/notsupport.php) then if use still want to use their browse, they can click to a link to go http://mysite.com/forum
If they direct access to mysite.com/forum then it will move to mysite.com/index.php but when go to index.php, it will check user browser then if firefox it display, if it's not firefox, it will move to mysite.com/notsupport.php then click to a link to go to mysite.com/forum, and so on
I'm sorry if my ideas is not clearly and my bad english.
Thank you so much for your help.
huyhoa
 
Posts: 35
Joined: Tue Nov 28, 2006 2:25 am

Postby richardk » Tue Jun 02, 2009 10:28 am

Why?

You can match the HTTP_USER_AGENT like the above matches against the HTTP_REFERER.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby huyhoa » Tue Jun 02, 2009 10:48 am

richardk wrote:Why?

You can match the HTTP_USER_AGENT like the above matches against the HTTP_REFERER.


Thank for reply richardk
But i dont know how to do. I dont know which one is right, firefox or mozilla
and all other
Can you please help me?
huyhoa
 
Posts: 35
Joined: Tue Nov 28, 2006 2:25 am

Postby richardk » Tue Jun 02, 2009 11:07 am

I dont know which one is right, firefox or mozilla

Neither do I. A search for "firefox user agent -switcher" found UserAgentString.com - List of Firefox User Agent Strings.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby huyhoa » Tue Jun 02, 2009 11:22 am

richardk wrote:
I dont know which one is right, firefox or mozilla

Neither do I. A search for "firefox user agent -switcher" found UserAgentString.com - List of Firefox User Agent Strings.


Thanks richardk. So, is this allright? i try but it's not work
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_USER_AGENT} !^Mozilla$ [NC]
RewriteRule \.*$ /notsupport.php [NC,L]

Is there anything wrong here?
Can you please help me repair it?
huyhoa
 
Posts: 35
Joined: Tue Nov 28, 2006 2:25 am

Postby richardk » Tue Jun 02, 2009 11:36 am

Code: Select all
^Mozilla$

matches only "Mozilla" because it has ^ (the beginning) and $ (the end). You could want to remove the ^ and $ so it will match anything containing Mozilla.

!^Mozilla$

"Mozilla" won't work, look at, for example, Internet Explorer's user agent. Other browsers (some here) might have a user agent containing Firefox.

Code: Select all
RewriteRule \.*$ /notsupport.php [NC,L]

will also match the request to /notsupport.php and cause a loop. You need
Code: Select all
RewriteRule !^notsupport\.php$ /notsupport.php [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby huyhoa » Tue Jun 02, 2009 6:46 pm

richardk wrote:
Code: Select all
^Mozilla$

matches only "Mozilla" because it has ^ (the beginning) and $ (the end). You could want to remove the ^ and $ so it will match anything containing Mozilla.

!^Mozilla$

"Mozilla" won't work, look at, for example, Internet Explorer's user agent. Other browsers (some here) might have a user agent containing Firefox.

Code: Select all
RewriteRule \.*$ /notsupport.php [NC,L]

will also match the request to /notsupport.php and cause a loop. You need
Code: Select all
RewriteRule !^notsupport\.php$ /notsupport.php [L]


Well, thanks richardk.
I try this:
Code: Select all
RewriteCond %{HTTP_USER_AGENT} !Firefox [NC]
RewriteRule !^notsupport\.php$ /notsupport.php [L]

Then, it's work, but, have a problem.
Because it check user agent, so it cannot load images, css, .... when it display notsupport.php page, and when go to mysite.com/forum too.
I dont know how to fix it. Could you please take a moment to fix it for me?
Thank you so much!
huyhoa
 
Posts: 35
Joined: Tue Nov 28, 2006 2:25 am

Postby richardk » Wed Jun 03, 2009 12:32 pm

Add exceptions, eg.
Code: Select all
RewriteCond %{REQUEST_URI} !^/path/to/style.css$
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby huyhoa » Wed Jun 03, 2009 5:38 pm

richardk wrote:Add exceptions, eg.
Code: Select all
RewriteCond %{REQUEST_URI} !^/path/to/style.css$


Thank for your reply.
But what's matter if i use many styles file and images too.
How do i add exception for all images file and style file?
huyhoa
 
Posts: 35
Joined: Tue Nov 28, 2006 2:25 am

Postby richardk » Thu Jun 04, 2009 1:22 pm

Are they in a specific directory?
Do they have specific file extensions?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Next

Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 96 guests

cron