SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2008
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how do I do this really SIMPLE thing with htaccesS?

    Ive read a 100 damn tutorials online, posted in forums, and I still don't have this thing working. everything becomes way more complex than it needs to be and all I need is one freakin line of code

    i have several subpages, index.php, products.php, bios.php and so on, and I want htaccess to hide the .php part so it simply becomes /products, /bios and thats it.

    this is what I have so far but it doesnt appear to work. I have no idea if this is even right but it's what someone told me to put, and it doesn't work.

    Code:
    Options +FollowSymlinks
    RewriteEngine on
    
    RewriteRule ^/?([a-z]+)$ $1.php [L]

  2. #2
    SitePoint Zealot
    Join Date
    Apr 2002
    Location
    Sydney, Australia
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You want it to be hidden in the browser, so when you go:

    www.mydomain.com/products.php

    it becomes

    www.mydomain.com/products

    ??

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2008
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, that is correct

  4. #4
    SitePoint Zealot
    Join Date
    Apr 2002
    Location
    Sydney, Australia
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not that hot on mod_rewrite, but I think it's designed to do the exact OPPOSITE of what you're suggesting. You can try it out, but it looks like it does:

    www.mydomain.com/products

    it becomes

    www.mydomain.com/products.php


    To do the way you're intending, AND make it show in the browser properly, the long way around is to make all your subpages redirect to folders and in the folders have an index.php that contains the real content.


    Someone else might have a better answer though ...

  5. #5
    SitePoint Enthusiast
    Join Date
    May 2008
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i tried that but it adds a trailing slash which I don't think looks as professional as just /products

  6. #6
    SitePoint Enthusiast
    Join Date
    May 2008
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    any other ideas?

  7. #7
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    t.e,

    Your mod_rewrite code is perfect (will work on both Apache 1.x and Apache 2.x). If it's not working, check that mod_rewrite is enabled (and using .htaccess) per the directions in my signature's linked tutorial.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  8. #8
    SitePoint Enthusiast
    Join Date
    May 2008
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i've done the .htaccess test and I successfully saw "This is a PHP File!" However when I do phpinfo() I don't see mod_rewrite even listed.

  9. #9
    SitePoint Enthusiast
    Join Date
    May 2008
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I talked to them and the host people said many people do mod_rewrite and that it is enabled....

    I'm not sure what else could be wrong.

  10. #10
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    t.e,

    Are you using ONLY lowercase letters? Since that's what's specified by the regex, I'll bet you've added other characters. What is your test URI (URL without the domain)?

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  11. #11
    SitePoint Enthusiast
    Join Date
    May 2008
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    alright I'm still not quite sure what that means so I tell you all of this....

    my website (im not sure if this is test or not but)

    www.mysite.com/ (I can click THAT and it actually goes to it and stays like that.. If I click bios however, and then hit 'home' again it then shows up as www.mysite.com/index.php)

    What its really going to though when you first go to it is www.mysite.com/index.php (all lowercase)

    In addition in the public_html folder, I have

    .htaccess, bios.php, products.php, index.php, about.php (all lowercase)

    In .htaccess I have this EXACTLY, lowercase and uppercase just as it appears:

    Code:
    Options +FollowSymlinks
    RewriteEngine on
    
    RewriteRule ^/?([a-z]+)$ $1.php [L]
    I appreciate your help man, I'm just trying to code my site and this seriously is baffling beyond belief to me, especially when I'm generally very good at this stuff.... Thanks again very much

  12. #12
    SitePoint Enthusiast
    Join Date
    May 2008
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh **** I just thought of something..... damn this is probably it.

    We had originally bought a domain name but it turned out it was way too long, so we bought another one which is shorter and pointed it to that directory on the host (we bought the domain from the same company, but the long domain was still the 'default' hosting domain).

    Could that interfere with it?

  13. #13
    SitePoint Enthusiast
    Join Date
    May 2008
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I took a picture if this helps at all.....


  14. #14
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    t.e,

    No, the test (IF you're referring to the test in my tutorial article) is whether the PHP or HTML version of the page is delivered when the HTML version is requested (but redirected by .htaccess's mod_rewrite to the PHP version).

    Okay, since you're lowercase only,
    Code:
    RewriteEngine on
    RewriteRule ^/?([a-z]+)$ $1.php [L]
    should work for you (for index, bios, about, etc). If it doesn't, there IS something wrong with your server (mod_rewrite is NOT enabled by default - and not all hosts will enable it). In other words, have another read through my tutorial as it will clear that up for you very quickly.

    Baffling? It's just regex in a confined environment!

    Your domain name has nothing to do with the {REQUEST_URI} (which is the variable that a RewriteRule operates on).

    Your image merely confirmed lowercase names (and that the ([a-z]+) atom is correct).

    CONFIRM that mod_rewrite is enabled!

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


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
  •