Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

.htaccess

I'm using a script at a sub-directory of my website. However, as of now, the script isn't responsive and it's very difficult to use on mobile devices. So, I'd like to redirect the mobile users to a web page on my site which will show them that the script isn't available on mobile devices. I searched on Google, but, I got the .htaccess codes that were giving me 500 errors.

So, can someone give me a proper required .htaccess code. I want to redirect mobile users who are trying to visit https://www.thevhgroup.ml/Product(s)/Koditor/editor/ to https://www.thevhgroup.ml/unavailable.html (this page isn't made yet but that's gonna be it's URL). If it isn't possible with .htaccess, how else can I redirect just the mobile users?

Any help will be appreciated.

Comments

  • There should be a redirection area on your CPanel.
  • Dude, I want to redirect only mobile browsers. Also, redirection in cPanel doesn't let me redirect only a sub-directory. Duh.

  • edited April 6

    @VPHrishikesh

    Well I have that htaccess code long ago,
    that I forgot which I deleted long ago and I kinda forgot...

    But I have other option which will actually works!
    First create a subdomain that you want to use for ur users
    (e.g. m.facebook.com, m.youtube.com)

    Second Create a mobile friendly website using a sitebuilder
    *Note: If u have already, skip this

    Third, Go to cloudflare

    Four, Go to the speed section

    Fifth, Configure the Mobile Redirect
    Like: Choose the subdomain for your mobile responsive website (e.g. m.yourdomain.tld)
    then turn the Mobile Redirect Option to on

    Sixth: Give it a test

    Seventh: Sub to my YT channel! JK, joke! XD

    *Important note:
    Your mobile responsive subdomain can be anything what you want like:
    Changing m.domain.tld to myresponsive.domain.tld

    Cheers,
    UK11

  • I know the mobile redirect option, but, it'll redirect my entire domain. My main website's responsive. I just don't want that sub-directory to redirect and not my entire domain.

  • edited April 6

    `> @VPHrishikesh said:

    I know the mobile redirect option, but, it'll redirect my entire domain. My main website's responsive. I just don't want that sub-directory to redirect and not my entire domain.`

    Now I understand you...
    If SitePro was still here right now then I can help you!
    but sadly its gone...

    U can visit my website and try it on two different browsers on two different devices! (e.g. visiting using chrome in android and visiting using IE on PC)
    Visit it: https://amourshipping.gq

    I think my website's feature to actually detect screed width is what you want right now,
    Am I right?

  • edited April 6

    Sir, with all due respect, No is my answer!

    I know how to make responsive websites. I just want to redirect a particular subdirectory. For example, main website can be here: domain.tld which is responsive!

    I have many more websites which I haven't hosted on sub-domains (like sub.domain.tld). I have hosted them in sub-directories (like domain.tld/otherwebsite/page1.html - This is NOT a page on my website, it's a sub-directory, a folder in short). So, likewise, I just want to redirect that particular sub-directory!

    If you still didn't understand, I'm sorry, I don't really think I can clear more on this. This was my best attempt.

  • edited April 6

    @VPHrishikesh
    You seem to not understand my last reply...
    and also you seem not to be doing about what I said about visiting my website on different platform...
    I didn't say you cant make a responsive website...

    I mean about the a code screen detection that will actually detect your screen width or screen height and change the layout of the website depends on what your screen width or height is,
    For example:
    I am visiting my site on android and when it detects my screen width that is an android size then it will refresh my website and change its layout to my responsive layout that I made!

    Does this clear you?

  • Exactly. That's what's being responsive. What am I asking is, I want to 'redirect' a folder of my website to another webpage when it's visited from a mobile device. Because, the script I'm using is not made by me and I haven't really made its css for us to be able to see it well on a mobile device.

  • @VPHrishikesh

    Just feel free to use developer tools on my website and find that code cause I don't have time to find it...
    But I am going to work on finding it too you know to help you!

  • edited April 6

    I'm saying, I don't want to resize my content to browser width in that folder. I want to resize the folder to another webpage if it's visited from a mobile device.

  • Okay I do not fully understand...

    So u want to redirect for example /folder to /newfolder if visited on mobile phone,
    Right?

  • edited April 6

    Yeah. Almost. Just that, I don't want to redirect to /newfolder I want to redirect to a webpage like /newpage.html. But yeah, either ways, the code should almost be the same. So, yeah, you've now understood the problem.

  • To redirect mobile users, you first need to reliably detect whether someone is a mobile user or not. That generally involves browser User Agent checks to whitelist or blacklist specific browsers.

    I think you may be able to find some huge, complex regular expression somewhere on the web which can do that, but it's not going to be perfect.

    The web doesn't provide any easy way to distinguish device types, so you can't do something simple like RewriteCond %{HTTP_MOBILE} yes to distinguish mobile and non-mobile devices.

  • @Admin

    Can you please give me the full code that I might need to redirect users from thevhgroup.ml/Product(s)/Koditor/editor to thevhgroup.ml/unavailable.html? I'm not very good with .htaccess codes yet.

  • @VPHrishikesh said:
    @Admin

    Can you please give me the full code that I might need to redirect users from thevhgroup.ml/Product(s)/Koditor/editor to thevhgroup.ml/unavailable.html? I'm not very good with .htaccess codes yet.

    Again: there is no easy .htaccess code I can just write out for a mobile redirect. I'd have to Google for examples as well, which I don't doubt you're capable of as well. Did you search for examples yourself already?

  • Yeah. As I have said in my OP, most codes gave me 500 error. I have also posted this on Stack Overflow since a week, but, nothing there too.

  • edited April 6

    @VPHrishikesh said:
    Yeah. Almost. Just that, I don't want to redirect to /newfolder I want to redirect to a webpage like /newpage.html. But yeah, either ways, the code should almost be the same. So, yeah, you've now understood the problem.

    Could you share one (or more) of the codes you used here so we can take a look at it? Maybe it can be fixed with a few tweaks.

  • edited April 6
    • I found this one, but, I don't know which all UAs to incude in mobile browser:

    RewriteCond %{HTTP_USER_AGENT} Opera
    RewriteRule ^abc.html$ http://example.com/xy/opera.html [R=301]

    RewriteEngine On

    # Check if this is the noredirect query string
    RewriteCond %{QUERY_STRING} (^|&)noredirect=true(&|$)
    # Set a cookie, and skip the next rule
    RewriteRule ^ - [CO=mredir:0:%{HTTP_HOST},S]

    # Check if this looks like a mobile device
    # (You could add another [OR] to the second one and add in what you
    # had to check, but I believe most mobile devices should send at
    # least one of these headers)
    RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
    RewriteCond %{HTTP:Profile} !^$
    # Check if we're not already on the mobile site
    RewriteCond %{HTTP_HOST} !^m.
    # Check to make sure we haven't set the cookie before
    RewriteCond %{HTTP:Cookie} !\smredir=0(;|$)
    # Now redirect to the mobile site
    RewriteRule ^ http://m.example.org%{REQUEST_URI} [R,L]

  • In the first code in the comment above, I tried including the UAs mentioned in the scripts from the link I have given, but, that threw a 500 error.

  • @VPHrishikesh said:

    • I found this one, but, I don't know which all UAs to incude in mobile browser:

    RewriteCond %{HTTP_USER_AGENT} Opera
    RewriteRule ^abc.html$ http://example.com/xy/opera.html [R=301]

    Simple enough (although it's missing the RewriteEngine On statement in case you were wondering why it didn't work). But you'd have to write and maintain the list of specific user agent filters yourself, which is tricky.

    @VPHrishikesh said:

    That looks quite interesting actually.

    I see two options to use their templates:

    • Use the Apache option and copy it to a .htaccess file on your account, and change the URL on the last line in the file.
    • Use the PHP option and copy the code to the top of your own script. This, of course, only works if you write the software yourself (and you're more comfortable writing PHP than fiddling with .htaccess rules).

    The .htaccess file works essentially the same as you described in option one, but comes with a fairly complete filter set already.

    @VPHrishikesh said:

    • Here's another one that I think I had tried:

    RewriteEngine On

    # Check if this is the noredirect query string
    RewriteCond %{QUERY_STRING} (^|&)noredirect=true(&|$)
    # Set a cookie, and skip the next rule
    RewriteRule ^ - [CO=mredir:0:%{HTTP_HOST},S]

    # Check if this looks like a mobile device
    # (You could add another [OR] to the second one and add in what you
    # had to check, but I believe most mobile devices should send at
    # least one of these headers)
    RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
    RewriteCond %{HTTP:Profile} !^$
    # Check if we're not already on the mobile site
    RewriteCond %{HTTP_HOST} !^m.
    # Check to make sure we haven't set the cookie before
    RewriteCond %{HTTP:Cookie} !\smredir=0(;|$)
    # Now redirect to the mobile site
    RewriteRule ^ http://m.example.org%{REQUEST_URI} [R,L]

    The nice thing of this code is that it actually allows you to redirect people to your mobile site, but also lets you provide a "View Desktop Site" button by setting a cookie or adding stuff to a URL to prevent people from being redirected again right away.

    On the other hand, this code doesn't do much in terms of device detection. It only checks for the x-wap-profile and Profile headers, which I don't think any smart phone actually sends.

  • Yeah. The apache script from that website worked! Thanks for the help!

This discussion has been closed.