How do you make urls look like they're in the root directory?

Discussion in 'Programming' started by CineWeekly.com, Jan 11, 2011.

  1. #1
    A lot of sites I frequent appear to have their articles in their root directory. I don't think that's the case because that would clog it up very quickly. I'm guessing the files are really in a subfolder and they're using something to make the URL look different:

    URL looks like:
    example.com/article.html

    File is really located in:
    example.com/folder/subfolder/article.html

    How is this accomplished?
     
    CineWeekly.com, Jan 11, 2011 IP
  2. IAreOwn

    IAreOwn Active Member

    Messages:
    46
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    95
    #2
    yeah, it's called mod rewrite or basically just rewriting the url for better seo... see this if you wanna know more http://www.easymodrewrite.com/
     
    IAreOwn, Jan 11, 2011 IP
  3. CineWeekly.com

    CineWeekly.com Greenhorn

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #3
    The thing is I've been asking in multiple Apache forums and no one can seem to figure out how to do it. We can get it to redirect but not rewrite. If you know of some sample code that should work let me know, we're all stumped.
     
    CineWeekly.com, Jan 11, 2011 IP
  4. mcfc4eva

    mcfc4eva Well-Known Member

    Messages:
    602
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    110
    #4
    Have you considered using PHP?

    You could include the whole page from a folder/subfolder etc.
     
    mcfc4eva, Jan 11, 2011 IP
  5. CineWeekly.com

    CineWeekly.com Greenhorn

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #5
    My pages are php but I don't know much about it. I only use it to include my frequently updated menu on all my pages. What exactly would I have to do to get this result? For my site personally the situation is:

    Currently (actual location):
    cineweekly.com/sunday/article.php

    Result (simulated location):
    cineweekly.com/article.php
     
    CineWeekly.com, Jan 11, 2011 IP
  6. mcfc4eva

    mcfc4eva Well-Known Member

    Messages:
    602
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    110
    #6
    Just create a new file (you can do this in notepad) and enter the code below
    
    <?php include("sunday/article.php"); ?>
    
    PHP:
    Save it as "article.php" and then upload it to your root folder.

    Done. :)

    Note: If you want to do this with other files then just change what's in the "quote marks" in the code and the name of the file you've created.
     
    mcfc4eva, Jan 11, 2011 IP
  7. CineWeekly.com

    CineWeekly.com Greenhorn

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #7
    The point is, I don't want a couple of hundred files in my root folder.
     
    CineWeekly.com, Jan 11, 2011 IP
  8. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Many websites are based on a Content Management System and therefore in the sense of their being a "www.domain.com/sundays_article.php" file isnt true, the files are all connected to the CMS and the content is actually all stored in a database.

    That said, what you are potentially wanting is a URL rewriting which is done via Apache's .htaccess or IIS' web.config

    As your talking about PHP I'd assume your using Apache and so have a look at the likes of http://www.addedbytes.com/for-beginners/url-rewriting-for-beginners/
     
    AstarothSolutions, Jan 12, 2011 IP
  9. CineWeekly.com

    CineWeekly.com Greenhorn

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #9
    We've already covered that we're dealing with Apache and .htaccess and this issue is certainly not a beginners problem because NO ONE on any Apache forum can solve it.
     
    CineWeekly.com, Jan 12, 2011 IP
  10. Minimal Hank

    Minimal Hank Peon

    Messages:
    136
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #10
    article.php
    <?php $article = $_GET['article']; include("directory/articles/$article.html"); ?>
    PHP:
    .htaccess
    Options +FollowSymLinks
    RewriteEngine On
    
    RewriteRule ^([a-zA-Z0-9-_]+).html$ article.php?article=$1 [R=301,NC]
    Code (markup):
    Haven't tested it ( .htaccess ) but it should work as expected.
     
    Minimal Hank, Jan 12, 2011 IP
  11. CineWeekly.com

    CineWeekly.com Greenhorn

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #11

    Where do I place this in the article or are you suggesting a separate file that only contains this?
     
    CineWeekly.com, Jan 12, 2011 IP
  12. Minimal Hank

    Minimal Hank Peon

    Messages:
    136
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #12
    It would be easier for you to manage it on a separate file as most probably your main page will not be the same as the one for viewing the article itself.
     
    Minimal Hank, Jan 12, 2011 IP
  13. CineWeekly.com

    CineWeekly.com Greenhorn

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #13
    Well with that solution I might as well just place the original article in the root. I'm trying to avoid having hundreds of files in my root directory two years from now.
     
    CineWeekly.com, Jan 12, 2011 IP
  14. Minimal Hank

    Minimal Hank Peon

    Messages:
    136
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Is /directory/articles/ your root directory ? No.
    The code I posted here does exactly what you were asking for.
    You either explain what you want to achieve or no one will be able to help you because of the lack of information.
     
    Minimal Hank, Jan 12, 2011 IP
  15. CineWeekly.com

    CineWeekly.com Greenhorn

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #15
    Haha, I've explained twice, it's very simple. I can't help it if you Apache "geniuses" can't understand a simple problem. First of all there isn't a folder called "articles", I said "article.php" as in the actual article. Even if you meant for the new php file to be in the "directory" folder that would still clog up that folder as well. There has to be a simple code that will make every url in:

    example.com/folder/

    Look like (not actually be in):
    example.com/
     
    CineWeekly.com, Jan 12, 2011 IP
  16. Minimal Hank

    Minimal Hank Peon

    Messages:
    136
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #16
    IMHO, you shouldn't be asking such questions if you don't know how to explain your goals.

    Now, tell me how it differs from what you have been asking for ? :confused:
     
    Minimal Hank, Jan 12, 2011 IP
  17. CineWeekly.com

    CineWeekly.com Greenhorn

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #17
    You're making this way more complicated than it is. It's simpler than a describing a 301 redirect but the solution is apparently difficult. All I want is my files located in a subdirectory but I want the user to see them as in the root without adding any files or updating code with every new article. That's the last time I'm saying it. It's common English.
     
    CineWeekly.com, Jan 12, 2011 IP
  18. Minimal Hank

    Minimal Hank Peon

    Messages:
    136
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #18
    Good luck then ;)
     
    Minimal Hank, Jan 12, 2011 IP
  19. loog12us

    loog12us Peon

    Messages:
    36
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #19
    put this in the .php file that you want to handle the articles , it could be index.php or articles.php

    Be sure to account for RFI when you use include function
     
    loog12us, Jan 13, 2011 IP
  20. CineWeekly.com

    CineWeekly.com Greenhorn

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #20
    Wouldn't that cause me to have a file in the root for every time I want to do this? That would defeat the purpose.
     
    CineWeekly.com, Jan 13, 2011 IP