Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6778971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:19:47+00:00 2026-05-26T16:19:47+00:00

I have dug high and low around Google and StackOverflow to try and figure

  • 0

I have dug high and low around Google and StackOverflow to try and figure out my problem, trying countless solutions but nothing has completely worked.

I’m looking to move the web root of the main domain on my server to a sub-directory. What I have currently for a server path to my web root:

/home/user/public_html/MyWebFilesHere

What I’m looking to have:

/home/user/public_html/subdir/MyWebfilesHere

When I browse to mydomain.com, there should be no visible difference though (i.e. “subdir” not visible after redirect).

Unfortunately, I am restricted to doing this purely with a .htaccess file since I’m on shared hosting and don’t have access to Apache config files and such. 🙁

What I currently have in my .htaccess in public_html is:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$
RewriteCond %{REQUEST_URI} !^/subdir/
RewriteRule ^(.*)$ /subdir/$1 [L]

This successfully redirects all queries to the sub-directory, however there’s a really weird issue. If I go to

mydomain.com/Contact/

it works great, redirecting the query to the path /subdir/Contact/ but leaving the address bar alone. If I go to

mydomain.com/Contact

(Note the lack of a trailing ‘/’) though, what shows in the address bar is

mydomain.com/subdir/Contact/

which isn’t what I want since “subdir” is showing.

For a working example on my actual site, try browsing to

colincwilliams.com/Contact/

compared with

colincwilliams.com/Contact

Do you guys have any ideas on how to make this work silently both with and without a trailing slash?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:19:48+00:00Added an answer on May 26, 2026 at 4:19 pm

    This is probably happening because mod_dir (the module that automatically redirects the browser if a request for a directory is missing a trailing slash to the same thing with a trailing slash. See the DirectorySlash directive in mod_dir

    What’s happening is:

    1. You request: mydomain.com/Contact
    2. mod_dir doesn’t touch this since /Contact isn’t a directory
    3. /Contact gets rewritten to /subdir/Contact and internally redirected
    4. mod_dir sees that /subdir/Contact is a directory and missing the trailing slash so it redirects the browser to mydomain.com/subdir/Contact/
    5. So now, your browser’s location bar has the /subdir/ in it.

    You can add DirectorySlash off in your .htaccess to turn off mod_dir from redirecting. But if you want directories to have trailing slashes, you can add a separate condition for it. Based on what you already have, we can expand it to this:

    RewriteEngine on
    
    # Has a trailing slash, don't append one when rewriting
    RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$
    RewriteCond %{REQUEST_URI} !^/subdir/
    RewriteCond %{THE_REQUEST} ./\ HTTP/1\.[01]$ [OR]
    # OR if it's a file that ends with one of these extensions
    RewriteCond %{REQUEST_URI} \.(php|html?|jpg|gif|css)$
    RewriteRule ^(.*)$ /subdir/$1 [L]
    
    # Missing trailing slash, append one
    RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$
    RewriteCond %{REQUEST_URI} !^/subdir/
    RewriteCond %{THE_REQUEST} [^/]\ HTTP/1\.[01]$
    # But only if it's not a file that ends with one of these extensions
    RewriteCond %{REQUEST_URI} !\.(php|html?|jpg|gif|css)$
    RewriteRule ^(.*)$ /subdir/$1/ [L]
    

    Note: I changed !^/mydomain/ to !^/subdir/, figured it was a typo because without it, mod_rewrite would loop internally indefinitely (foo -> /subdir/foo -> /subdir/subdir/foo -> /subdir/subdir/subdir/foo, etc). If I got that wrong, you can change it back.

    Edit: See my additions of RewriteCond’s matching against \.(php|html?|jpg|gif|css). These are the file extensions that get passed through without getting trailing slashes added. You can add/remove to suit your needs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with google adview... it's not showing up. I dug around
I've dug through all the tutorials and have been pulling my hair out trying
I have been trying to get TTTabItem to work with images. And I dug
I've dug around through previously asked questions and have had no luck finding a
I've dug around for a while on Google and here on stack Overflow and
I have dug through a number of posts here and looked over google labs
I am new to Unit Testing and think I might have dug myself into
After years in embedded programming, I have to develop a Windows app. I dug
Have just started using Google Chrome , and noticed in parts of our site,
Have a n-tire web application and search often times out after 30 secs. How

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.