htaccess redirect except 1 page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • adamjblakey
    New Member
    • Jan 2008
    • 133

    htaccess redirect except 1 page

    Hi,

    I am using the following code to redirect my site to a mobile site:

    Code:
    #redirect mobile browsers
    RewriteCond %{HTTP_USER_AGENT} ^.*iPhone.*$
    RewriteRule ^(.*)$ http://www.mysite.mobi/ [R=301]
    RewriteCond %{HTTP_USER_AGENT} ^.*BlackBerry.*$
    RewriteRule ^(.*)$ http://www.mysite.mobi/ [R=301]
    RewriteCond %{HTTP_USER_AGENT} ^.*Palm.*$
    RewriteRule ^(.*)$ http://www.mysite.mobi/ [R=301]
    Which works fine however i have one URL which is:

    http://www.mysite.co.u k/adminxx/login

    That i dont want redirected if i go to this on my mobile. Is there a way to do this?

    Cheers,
    Adam
  • Sudaraka
    New Member
    • Jan 2011
    • 55

    #2
    You can add a condition to each rule to make sure the request uri does not contain /adminxx/login
    Code:
    RewriteCond %{REQUEST_URI} !^adminxx\/login
    Or, you can make it skip these rewrites if the request is for /adminxx/login
    Code:
        #redirect mobile browsers
        RewriteRule ^adminxx\/login - [S=6] #no rewrite, just skip next 6 lines
        RewriteCond %{HTTP_USER_AGENT} ^.*iPhone.*$
        RewriteRule ^(.*)$ http://www.mysite.mobi/ [R=301]
        RewriteCond %{HTTP_USER_AGENT} ^.*BlackBerry.*$
        RewriteRule ^(.*)$ http://www.mysite.mobi/ [R=301]
        RewriteCond %{HTTP_USER_AGENT} ^.*Palm.*$
        RewriteRule ^(.*)$ http://www.mysite.mobi/ [R=301]
    Note: you'll have to watch the number 6 in [S=6] when you modify the rules later because line count could change.
    See http://httpd.apache.org/docs/2.0/mod...ml#rewriterule

    Comment

    • adamjblakey
      New Member
      • Jan 2008
      • 133

      #3
      Thank you very much for your reply. I have tried both variations but neither seem to work. Can you see any reason why these would not work?

      Comment

      • Sudaraka
        New Member
        • Jan 2011
        • 55

        #4
        Try it with the starting /
        Code:
        RewriteCond %{REQUEST_URI} !^\/adminxx\/login
        Code:
        RewriteRule ^\/adminxx\/login - [S=6]

        Comment

        • adamjblakey
          New Member
          • Jan 2008
          • 133

          #5
          Sorry tried again but this still does not work. Any other options?

          Comment

          • Sudaraka
            New Member
            • Jan 2011
            • 55

            #6
            hmm, not sure what's going on.
            Try turning on rewrite log and see how your request goes through the rules you have.

            Comment

            • adamjblakey
              New Member
              • Jan 2008
              • 133

              #7
              Thanks for your help so far, i dont have access to the rewrite log to turn this on as i am on a shared hosting package. Is there anything else i can do at all?

              Comment

              Working...