Results 1 to 6 of 6
  1. #1
    Designer
    Programmer
    Smiley's Avatar
    Join Date
    Oct 2011
    Location
    Behind You
    Posts
    1,081
    Points
    1,463
         User Info     Contact     Gamer ID
    Join Date
    Oct 2011
    Location
    Behind You
    Posts
    1,081
    Points
    1,463

    Default Trouble with the .htaccess Rewrite

    I am trying to create an .htaccess file so that when people visited a website on their smartphones,
    they would automatically be redirected to the mobile friendly version of the site.

    I have been racking my brain, googling the shit out of ideas, and still cannot get it to do what it
    is supposed to do. Here is what the .htaccess file looks like:
    PHP Code:
    Put this in your root directoryat the end of your existing .htaccess file.
    This will redirect the user to a mobile version of your website on a subdomain.
    If 
    you don't want them to go to the same path, eliminate the $1 in the redirect URL.

    # Do not remove this line, otherwise mod_rewrite rules will stop working
    RewriteBase /

    RewriteCond %{REQUEST_URI} !^/mobiledirectoryhere/.*$
    RewriteCond %{HTTP_ACCEPT} "text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml" [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} "sony|symbian|nokia|samsung|mobile|windows ce|epoc|opera|operamini|fennec|miren" [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} "mini|nitro|j2me|midp-|cldc-|netfront|mot|up\.browser|up\.link|audiovox"[NC,OR]
    RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ericsson,|panasonic|philips|sanyo|sharp|sie-"[NC,OR]
    RewriteCond %{HTTP_USER_AGENT} "portalmmm|blazer|avantgo|danger|palm|series60|palmsource|pocketpc"[NC,OR]
    RewriteCond %{HTTP_USER_AGENT} "smartphone|rover|ipaq|au-mic,|alcatel|ericy|vodafone\/|wap1\.|wap2\.|iPhone|android"[NC]
    RewriteRule (.*) http://THE_MOBILE-VERSION_WEBSITE.com [L,R=301]


    // Yes I changed the http://THE_MOBILE-VERSION_WEBSITE.com to what it needs to be.

    // Should this line stay the same or does it need changed???
    RewriteCond %{REQUEST_URI} !^/mobiledirectoryhere/.*$ 
    This .htaccess file is saved in the ROOT of the entire website directory.

    However, when I go the website on my smartphone, it DOES NOT auto-redirect to the mobile version, that I set it to.

    Anyone have experience with .htaccess files and can help me figure this issue out?

    0 Not allowed! Not allowed!
    Last edited by Smiley; 02-25-2012 at 01:39 PM.
    I did it for the lulz.
    I did it for the lulz.
    I did it for the lulz.

  2. #2
    fear_bot
    Guest

    Default

    Don't know if this will help or not, but on one of the web hosts I've used they allowed you to choose where the .htaccess is at and whether to use .htaccess or not.

    0 Not allowed! Not allowed!

  3. #3
    Designer
    Programmer
    Smiley's Avatar
    Join Date
    Oct 2011
    Location
    Behind You
    Posts
    1,081
    Points
    1,463
         User Info     Contact     Gamer ID
    Join Date
    Oct 2011
    Location
    Behind You
    Posts
    1,081
    Points
    1,463

    Default

    I got it figured out..

    I was leaving out the most important part lol: "RewriteEngine On"

    So it SHOULD look like this in the .htaccess file:
    PHP Code:
    # Do not remove this line, otherwise mod_rewrite rules will stop working
    RewriteEngine On
    RewriteBase 
    /

    RewriteCond %{REQUEST_URI} !^/mobiledirectoryhere/.*$
    RewriteCond %{HTTP_ACCEPT"text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml" [NC,OR]
    RewriteCond %{HTTP_USER_AGENT"sony|symbian|nokia|samsung|mobile|windows ce|epoc|opera|operamini|fennec|miren" [NC,OR]
    RewriteCond %{HTTP_USER_AGENT"mini|nitro|j2me|midp-|cldc-|netfront|mot|up\.browser|up\.link|audiovox"[NC,OR]
    RewriteCond %{HTTP_USER_AGENT"android|blackberry|ericsson,|panasonic|philips|sanyo|sharp|sie-"[NC,OR]
    RewriteCond %{HTTP_USER_AGENT"portalmmm|blazer|avantgo|danger|palm|series60|palmsource|pocketpc"[NC,OR]
    RewriteCond %{HTTP_USER_AGENT"smartphone|rover|ipaq|au-mic,|alcatel|ericy|vodafone\/|wap1\.|wap2\.|iPhone|android"[NC]
    RewriteRule (.*) http://THE_MOBILE-VERSION_WEBSITE.com [L,R=301] 
    Problem solved now. I feel so "dee-dee-deeeee" right now. Sorry for the waste of a thread post.

    0 Not allowed! Not allowed!
    I did it for the lulz.
    I did it for the lulz.
    I did it for the lulz.

  4. #4
    Robot Universe Owner
    Creator of DarkFrost
    demon450's Avatar
    Join Date
    Apr 2010
    Location
    New York
    Posts
    2,704
    Points
    6,191
         User Info     Contact     Gamer ID
    Join Date
    Apr 2010
    Location
    New York
    Posts
    2,704
    Points
    6,191
    Gamer IDs

    Gamertag: Medius450 PSN ID: Medius1337

    Contact info:

    Youtube Channel: http://www.youtube.com/user/Roceso1337

    Default

    u started to comment with // is probably why

    0 Not allowed! Not allowed!
    Check out Darkfrost
    Check out Robot Universe






  5. #5
    Designer
    Programmer
    Smiley's Avatar
    Join Date
    Oct 2011
    Location
    Behind You
    Posts
    1,081
    Points
    1,463
         User Info     Contact     Gamer ID
    Join Date
    Oct 2011
    Location
    Behind You
    Posts
    1,081
    Points
    1,463

    Default

    Quote Originally Posted by demon450 View Post
    u started to comment with // is probably why
    I hope that was sarcasm because..

    You CAN use // to comment out parts in code. But I was using it as a kind of, READ THIS COMMENT PEOPLE WHO CAN HELP.

    0 Not allowed! Not allowed!
    I did it for the lulz.
    I did it for the lulz.
    I did it for the lulz.

  6. #6
    Robot Universe Owner
    Creator of DarkFrost
    demon450's Avatar
    Join Date
    Apr 2010
    Location
    New York
    Posts
    2,704
    Points
    6,191
         User Info     Contact     Gamer ID
    Join Date
    Apr 2010
    Location
    New York
    Posts
    2,704
    Points
    6,191
    Gamer IDs

    Gamertag: Medius450 PSN ID: Medius1337

    Contact info:

    Youtube Channel: http://www.youtube.com/user/Roceso1337

    Default

    oic, i never commented in the htaccess file but owell u said its fixed :P

    0 Not allowed! Not allowed!
    Check out Darkfrost
    Check out Robot Universe






Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -10. The time now is 08:26 AM.
Powered by vBulletin®
Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.