SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Mar 2004
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Remove folder name from URL file path

    Currently the website's files are located in the root folder with the following htaccess file

    Code:
    DirectoryIndex home.php
    
    RewriteEngine on
    
    ## force www. ##
    RewriteCond %{HTTP_HOST} !^www.truedesign.no$
    RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301]
    
    ## remove .php and re-direct any .php-addresses##
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+php?\ HTTP
    RewriteRule (.+)\.php?$ http://www.domain.com/$1 [R=301,L]
    RewriteCond %{REQUEST_fileNAME} !-d
    RewriteCond %{REQUEST_fileNAME}\.php -f
    RewriteRule ^(.*)$ $1.php
    We want to move all our website files to a certain folder on the webspace to keep the root folder more tidy. I normally would just do something like this:

    Code:
    redirect 301 /index.html http://www.domain.com/foldername/
    This would give URLs like www.domain.com/foldername/ or www.domain.com/foldername/filename

    Is ther any way to remove 'foldername' from the URL? We really just want www.domain.com/filename and www.domain.com for the home page (although these files would be located in a folder).

    Many thanks.

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

    You've gone to a lot of trouble to reinvent the {IS_SUBREQ} using {THE_REQUEST} but it should work just fine! Congrats!

    I'd not move those files, if I were you, but your mod_alias Redirect will work as you indend (for index.html but why not name the DirectoryIndex in foldername, too?). That will work for index.html and the 301 will take the directory move to the browser for relative links.

    Okay, "remove foldername?" Certainly, mod_rewrite. Use a modified version of either your "loopy" code or either version of my (signature linked) "loopy" code. Be sure, though, to use the <base> tag to let browsers know which directory level to look for relative links!

    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
  •