PHP - How to get pretty or clean urls/links using HTACCESS - Full Tutorial[Part 1 of 2]

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 มิ.ย. 2017
  • A Good way to get pretty or clean URLs/links using HTACCESS and PHP
    Support me on patreon: / quickcode

ความคิดเห็น • 98

  • @abrahamtembo2454
    @abrahamtembo2454 2 ปีที่แล้ว +5

    Do more videos and project. You aren't just a great teacher but also a good presenter: so clear and consistent

    • @QuickProgramming
      @QuickProgramming  2 ปีที่แล้ว

      Thanks, will do! i appreciate your encouragement :)

  • @judyflorence5045
    @judyflorence5045 5 ปีที่แล้ว +4

    Actually this is the best video I have ever watched. I was just laughing at myself when I was watching this. Soooooo sweet, simple, on to the point.....It's every thing I have been looking for. Thanks MAN. I would request you to make a video on more about making HTACCESS .

    • @QuickProgramming
      @QuickProgramming  5 ปีที่แล้ว

      thanks and am glad it helped you out. i'll try and do more videos on htaccess

    • @souls.7033
      @souls.7033 5 ปีที่แล้ว

      i understand you man, this happens to me way often. You're looking for a solution for hours and hours and when you finally find it, the smile of joy comes out and you don't even notice it :D

  • @BraveDave
    @BraveDave 3 ปีที่แล้ว +2

    Great tutorial, QP! You explained it very clearly and I have finally managed to give my websites clean URLs. Thank you! :)

    • @QuickProgramming
      @QuickProgramming  3 ปีที่แล้ว +1

      Glad to hear it and you're most welcome. just make sure to see part 2 also on how to make sure images and css are visible when the url is longer

  • @sharookelbessa7472
    @sharookelbessa7472 ปีที่แล้ว

    iam happy with this tutorial and all tutorials you post your channel are very important. thank you very much.

  • @prof.rohitnambiar4492
    @prof.rohitnambiar4492 7 ปีที่แล้ว +1

    Great !! Have been wondering where i was missing my css files!!! Helped a lot! Thanks...

    • @QuickProgramming
      @QuickProgramming  7 ปีที่แล้ว

      you are most welcome, thanks alot for the comment

  • @IndexOption
    @IndexOption 6 ปีที่แล้ว +1

    I saw some other videos but this video really helped me, thanks !

  • @meinnameistmenko.4207
    @meinnameistmenko.4207 3 ปีที่แล้ว +1

    Omfg it finally worked. I searched for almost an hour.

  • @eUploads
    @eUploads ปีที่แล้ว +1

    Amazing tutorial! This helped me alot!

  • @marksiely4747
    @marksiely4747 2 ปีที่แล้ว

    Thank you very much for this video. I am getting stuck on my screen show the word Profile, appearing on screen what ever I write! Please help! Do you have an idea why this is happening? I am also getting : [REQUEST_METHOD] => GET
    [QUERY_STRING] => but QUERY_STRING IS NOT SHOWING, GETTING REQUEST_URI instead. thank you very much in advance

  • @envadd.6556
    @envadd.6556 ปีที่แล้ว

    This is probably the simplest and most practical version I seen on this subject. You are simple awesome my man!!
    I do have one questions though.. in HTACCESS how do I go about if I have admin page so I want link to go through admin and then public pages that go through index... how do I tell server there is two channels? should I just make new lines and add admin.php?$2

  • @justinguiriba8163
    @justinguiriba8163 2 หลายเดือนก่อน

    when i typed it, I cant access my website file in htdocs

  • @dindjarin360
    @dindjarin360 6 ปีที่แล้ว +1

    I tried this with xampp and it works but when I try this on a live server it doesnt work, why? Im able to do this configurations on my server 500 internal server error

    • @QuickProgramming
      @QuickProgramming  6 ปีที่แล้ว

      It means you have an error in your htaccess file. Check the text in there letter by letter and make sure it matches the one in the video. If you fail to find the problem, send me a screen shot of the htaccess file on Facebook here facebook.com/quickcode

  • @DownVolt
    @DownVolt 7 ปีที่แล้ว +1

    Great video ! Thank you a lot
    But I have a question, with this method, can we still register a new member on our website by redirecting on an other page, register.php for example.. ?

    • @QuickProgramming
      @QuickProgramming  7 ปีที่แล้ว

      yes you can. what you do is put all your register code inside the register.php file as you would normally. then redirect your user to e.g www.yourwebsite.com/register .everything will still go through the index file, but it will require the register.php file along the way and all the POST variables will also be available as they normally are. thats how i build all my sites so i know it works from experience. you can ask further questions if you find any problems using this method.

    • @TheCodersSoul
      @TheCodersSoul 6 ปีที่แล้ว

      Not working for, please me. Please help.

    • @QuickProgramming
      @QuickProgramming  6 ปีที่แล้ว

      Syed, what part exactly is not working?

    • @andrielejosilene2452
      @andrielejosilene2452 3 ปีที่แล้ว

      Cdc

    • @andrielejosilene2452
      @andrielejosilene2452 3 ปีที่แล้ว

      Vvvďvxd 😬😠😯😯😯😉😇😕😕😕😠😠😆 🔰💄⌚⌚⌚👓👠👙👙👙💲♐♐ 🔙🔙♉♉♏♐♈

  • @hssin4343
    @hssin4343 3 ปีที่แล้ว +1

    second comment with my second channel, thank you man again

  • @amanlatkar2961
    @amanlatkar2961 5 ปีที่แล้ว +1

    Hii sir i am having Nginx Engine for that what should i do , it's Urgent reply plz

    • @QuickProgramming
      @QuickProgramming  5 ปีที่แล้ว

      thats usually an online server error. does it still happen when you remove the HTACCESS file?

  • @devsabuj4818
    @devsabuj4818 2 ปีที่แล้ว

    If having more than one php file.. how do I make clean url for as per my requirement...?

    • @QuickProgramming
      @QuickProgramming  2 ปีที่แล้ว

      Just like in the tutorial, you can load each page into the index page as if they are separate pages. The index page acts as a routing system and not a real page. Also with part 2 of this tutorial

  • @ahmedhassine5837
    @ahmedhassine5837 3 ปีที่แล้ว +1

    thank you man

  • @johnthanaraaj6343
    @johnthanaraaj6343 ปีที่แล้ว

    Is the HTACESS work on wampserver?

  • @circulateads
    @circulateads 2 ปีที่แล้ว +1

    You are wonderful bro, I cherish your way of teaching, please I want to ask, how can we use this for a website that has user profile whereby user login and register?

    • @QuickProgramming
      @QuickProgramming  2 ปีที่แล้ว +1

      I have several videos here on signup and login but I don't think any of them use this system. You've just given me an idea for my next video. I'll make one in a the next 2 days

  • @ireneavaro7590
    @ireneavaro7590 6 ปีที่แล้ว

    Hi how are you ? i have url index.php?page=login and login redirect to customer.php?page=dashboard in this page have order this customer.php?page=dashboard&orderby=asc how rewrite friendly this url

    • @QuickProgramming
      @QuickProgramming  6 ปีที่แล้ว

      am fine thanks. my method will only work if you use one php page for the whole website, which is index.php, and then include the right pages depending on the url. this way you only need a few lines of code in the HTACCESS files, which is less confusing.
      so for your situation, after a user visits index.php?page=login,(www.yoursite.com/login) redirect them to index.php?page=customer&activity=dashboard&orderby=asc, which you can rewrite as www.yoursite.com/customer/dashboard/asc.
      this way no matter the url, all requests go through the index page and then the first parameter in the url determines what file will be included and displayed. the rest of the parameters(/dashboard/asc) are for the content

  • @kmaldar
    @kmaldar 6 ปีที่แล้ว +1

    it works for me . but as soon as my page is loaded it looks like a simple html page it removes css, js and images? how this problem can be solve???

    • @QuickProgramming
      @QuickProgramming  6 ปีที่แล้ว +2

      i think its because you're using relative paths to define your css file, js and images. e.g instead of you have to write like this in short, you have to ggive absolute paths. i explain this and how to do it dynamically in the second part of the video here-> th-cam.com/video/39ax8OgOGiw/w-d-xo.html

    • @kmaldar
      @kmaldar 6 ปีที่แล้ว

      i am doing this in locally and i have tried localhost......... but it does not work

    • @kmaldar
      @kmaldar 6 ปีที่แล้ว +1

      thanks now it works

    • @QuickProgramming
      @QuickProgramming  6 ปีที่แล้ว

      awesome, am happy to hear that :)

    • @kmaldar
      @kmaldar 6 ปีที่แล้ว

      i need ur help once more..... Please tell me how to remove %20 from url i mean currently my url is uppsc%20result and i want like this uppsc-result

  • @paagcdigitalpvt.ltd.7260
    @paagcdigitalpvt.ltd.7260 6 ปีที่แล้ว

    Not working for, please help me in codes.

  • @anupamakumari7481
    @anupamakumari7481 5 ปีที่แล้ว

    I tried hard but still not getting the result please help me

  • @happylittlemonk
    @happylittlemonk 5 ปีที่แล้ว +1

    This is good but it defies the purpose of htaccess and you should not user $_SERVER value directly. You are hacking it. The point of htaccess is to filter out these parameter before any files are parsed even.
    However the problem with htaccess is when it finds a match it leaves your url unchanged but returns the right url. So this is good method to clean the url
    in the index file you can check for all the files you have and what parameters they require and return only those and remove the junk
    usually the users do not temper with urls and the href within your code will always return correct format, so this is to make it super clean and fool proof

    • @QuickProgramming
      @QuickProgramming  5 ปีที่แล้ว

      true, its a hack. two things i like about this method are 1. since all urls are redirected to the index file, you dont need to write so many rewrite conditions in the htaccess file, which can get pretty confusing especially for beginners. 2. since all urls are redirected to the index file, if you want to shut down the website for maintenance, you only need to shut down the index file and the whole website goes offline. this prevents alot of headaches from my own real world experience, thats why i prefer this hack over the norms

    • @behzadkhokher7998
      @behzadkhokher7998 5 ปีที่แล้ว

      Where you used RewriteRule ^(.*)$ index.php can't we just do RewriteRule ^(.*)$ index.php?url=$1 and then use $_GET to retrieve the URL instead of the server global. Or would server global still be the better option?

    • @QuickProgramming
      @QuickProgramming  5 ปีที่แล้ว +1

      @@behzadkhokher7998 sure you can use that alternative. both _server and _get are globals so you can use what you're comfortable with. i only use _server because even if the query string is missing, as it would when someone is on the home page, server['query_string'] still exists, whereas _get will be empty. but that can be solved by checking whether it exists or not. its all about preference

    • @sheriffderek
      @sheriffderek 2 ปีที่แล้ว

      @@QuickProgramming I'd love to hear about what the norm is and how that works. I've seen versions where you write your links with the filepath syntax instead of query strings and then that's parsed in to the querystrings behind the scenes - and then that's masked but it was super confusing!

  • @Kareszkoma
    @Kareszkoma 4 ปีที่แล้ว +1

    Good, however I do not recommend making this structure. This structure is kind of barbaric. It's too simple. Later it will create problems. I do recommend having a central point, a controller, just like in the video. An url handler is good too. But rather invite code, than have subpages.

    • @QuickProgramming
      @QuickProgramming  4 ปีที่แล้ว

      thanks. this is just to show whats possible. i left it open for the programmer to do what they want with it. you can create a URL handler etc to handle things better as you code. i use this in my own projects and it hasn't created any problems so far. i use a very simple URL handler, which puts all variables in an array called $URL. so depending on which location the variable is, it determines what type it is, e.g [0] = page_name, [1] = controller, [2] = product, [3] = page_number etc. it also accounts for situations where other variables dont exist.
      i simply copy this handler from project to project and have never gone back to edit the code. but if theres a problem you're thinking of that i havent considered, i'll be happy to hear it so i can make a followup video to address that for the sake of others who dont know

  • @ddev-hub991
    @ddev-hub991 2 ปีที่แล้ว

    Wow 5yrs ago

  • @anupamakumari7481
    @anupamakumari7481 5 ปีที่แล้ว

    how to make localhost/spy%20bloger%20old/products.php?pid=Wireless%20Camera like localhost/spy%20bloger%20old/Wireless%20Camera

  • @thechoosen4240
    @thechoosen4240 ปีที่แล้ว

    Good job bro, JESUS IS COMING BACK VERY SOON;WATCH AND PREPARE