Results 1 to 2 of 2

Thread: Hide subdirectory in URL with rewrite

  1. #1
    New user
    Join Date
    09-07-09.
    Posts
    6

    Default Hide subdirectory in URL with rewrite

    Hi everybody, If anyone is an expert in url rewriting, I'd really appreciate your help with this one.

    Here's the background info - I'm redirecting an exact replica of the site, 'old-domain.tld' to the site, 'new-domain.tld/newdirectory'

    Using the following htaccess code in my OLD site's root,

    Redirect 301 / http://www.new-domain.tld/

    I have successfully managed to direct my files to the same filename in the root of the NEW site (obviously the files don't exist here, because they're in the subdirectory entitled 'newdirectory'...)

    So using the following htaccess code in the root of the NEW site,

    RewriteEngine on
    RewriteBase /
    RewriteRule ^$ newdirectory/ [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ newdirectory/$1 [L]

    I have manged to hide the subdirectory, 'newdirectory' from MOST of my urls (which are also htaccess coded to force users to www version and display search engine friendly .html endings without index.php).

    To get this to work, I also had to leave the base url or 'Relative Path to Contao Directory' in Contao's settings blank - so that all auto-generated relative links would NOT include the subdirectory, 'newdirectory'.

    So now, http://www.old-domain.tld/events.html successfully redirects you to http://www.new-domain.tld/events.html (with 'newdirectory' hidden from the url).

    The big BUT however, is that when I try to access the admin url for Contao or Typolight, it puts the 'newdirectory' back into the url - UNLESS I type a trailing slash.

    So, 'http://www.old-domain.tld/contao' takes me to 'http://www.new-domain.tld/newdirectory/contao'
    Whereas, 'http://www.old-domain.tld/contao/' takes me to 'http://www.new-domain.tld/contao' (where I want to be).

    Only problem is that users won't remember to type in the trailing slash.

    Once in the backend, depending on where you are, the 'newdirectory' is sometimes present, and sometimes not - plus it causes the user to be taken to random places within the backend when they press something like 'save and close' or 'go back'.

    I have noted the main difference here is that I am trying to rewrite a folder ('http://www.old-domain.tld/contao') instead of a filename ('http://www.old-domain.tld/events.html') or perhaps it's conflicting with some other redirect within Contao - but not sure how to remedy it.

    Please HELP!! :-)

  2. #2
    New user
    Join Date
    09-07-09.
    Posts
    6

    Default Re: Hide subdirectory in URL with rewrite

    Update - adding these lines to the htaccess in the root of the NEW site adds a trailing slash to the Contao admin url, which almost fixes my problem:

    RewriteCond %{REQUEST_URI} !(\.|/$)
    RewriteRule (.*) http://www.new-site.tld/$1/ [R=301,L]

    So http://www.old-site.tld/contao --> http://www.new-site.tld/newdirectory/contao -->
    http://www.new-site.tld/newdirectory/contao/ --> http://www.new-site.tld/contao/
    (because for some unknown reason it worked with a trailing slash)

    However, I still have the problem in the backend, where the subdirectory name is sometimes appearing in the url and causing otherwise predictable actions (such as 'save and close' or 'go back') to take the user to unpredicable places...

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
  •