Forum Moderators: phranque

Message Too Old, No Replies

Htaccess Code Not Working On Apache 2.2

         

trigoon

4:32 am on Feb 15, 2008 (gmt 0)

10+ Year Member



Hello,
Im still quite a novice when it comes to htaccess so im hoping someone here can help clear things up for me.

The problem is I have a hosting account at hostgator which runs an earlier version of apache. I need to redirect anyone who isnt using firefox, internet explorer or opera as a browser to another file. I made the following:

RewriteCond %{HTTP_USER_AGENT} !^Mozilla/5.0.*$ [NC]
RewriteCond %{HTTP_USER_AGENT} !^Mozilla/4\.[0-9]+\ \(compatible;\ MSIE\ [0-9.]+
RewriteCond %{HTTP_USER_AGENT} !^Opera/[0-9.]+
RewriteRule ^test/index.html [mysite.com...] [R=301,L]

The code seems to work fine on the hostgator hosting account. The problem is on my sever which runs apache 2.0+. For some odd reason the code doesnt work at all anymore, this problem has happened in the past as well when using other codes. I asked some people but all they could tell me was that the L flag may be causing problems, I tried removing it but still got the same problem.

Hope someone can help :)

phranque

6:28 am on Feb 15, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld [webmasterworld.com], trigoon!

have you removed the RewriteCond statements to see if it works without any conditions?

trigoon

1:43 pm on Feb 15, 2008 (gmt 0)

10+ Year Member



Thanks for the welcome :) Hmm so you mean removing the RewriteCond just to check if the problem is with the line RewriteRule ^test/index.html http://example.com/test/index.php [R=301,L] ? Ill test it out :)

[edited by: jdMorgan at 1:50 am (utc) on Feb. 16, 2008]
[edit reason] example.com [/edit]

jdMorgan

1:59 pm on Feb 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Also, this may just be a difference in the default server configurations, and not due the Apache version itself.

If not already configured, you will need:

In httpd.conf :


Allow Override All

and in .htaccess, preceding any other mod_rewrite directives :


Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine on

Note that -Multiviews and -Indexes are optional -- I suggest them for sanity and security, respectively. If in doubt, look them up in the Apache core Options documentation [httpd.apache.org].

Always completely flush your browser cache (or "Temporary Internet Files" in Internet Explorer) before testing any new code, otherwise, you are likely looking at the results of a cached server response.

If this does not help, please post specifics of how "it doesn't work" such as:

  • How did you test?
  • What were the results?
  • How did those results differ from your expectations?
  • What, if anything, appeared in your server error log?

    Jim

  • The Contractor

    2:18 pm on Feb 15, 2008 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    As jdMorgan states, make sure you have RewriteEngine on so in your case it would look like:

    RewriteEngine on
    RewriteCond %{HTTP_USER_AGENT} !^Mozilla/5.0.*$ [NC]
    RewriteCond %{HTTP_USER_AGENT} !^Mozilla/4\.[0-9]+\ \(compatible;\ MSIE\ [0-9.]+
    RewriteCond %{HTTP_USER_AGENT} !^Opera/[0-9.]+
    RewriteRule ^test/index.html http://example.com/test/index.php [R=301,L]

    [edited by: jdMorgan at 1:50 am (utc) on Feb. 16, 2008]
    [edit reason] example.com [/edit]

    trigoon

    8:11 pm on Feb 15, 2008 (gmt 0)

    10+ Year Member



    Hello,

    Thanks for all the replies. I tried what was said but it still doesnt seem to make a difference.

    Whats wrong:
    - It wont redirect someone when they arent using the required browsers
    - I tested it by removing the firefox conditional (RewriteCond %{HTTP_USER_AGENT} !^Mozilla/5.0.*$ [NC]) and going to the website with firefox, doesnt redirect.
    - The results differ because the code works fine on my hostgator hosting account.

    Thanks