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 9148819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:22:39+00:00 2026-06-17T11:22:39+00:00

Server by default redirects users who type example.com/folder to example.com/folder/ Is there any way

  • 0

Server by default redirects users who type example.com/folder to example.com/folder/

Is there any way to change that (for example when they go to example.com/folder to redirect to otherexample.com/folder/). But this has to affect all folders but exclude the root. Also the code should do nothing when they type example.com/folder/.

Edit

Also the code should not affect images and all other files (or better say, if the requested document has file extension), just folders.

example:

should affect : example.com/folder
              : example.com/folder/folder

but should not : example.com
               : example.com/forum (but only forum, only this folder)
               : example.com/folder/
               : example.com/folder/.
               : example.com/folder/folder/
               : example.com/image.png
               : example.com/something.something
               : example.com/something.
               : example.com/.something

Edit

And an other edit:
Let’s say we found the .htaccess code (the 1st answer below). How do I make it work for all my domain and website expect my blog (example.com/blog) which I don’t want to have redirections like whole my website?

  • 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-06-17T11:22:40+00:00Added an answer on June 17, 2026 at 11:22 am

    Server by default redirects users who type example.com/folder to
    example.com/folder/

    That’s done by mod_dir for several good reasons, all of which are explained in the DirectorySlash documentation. You could use DirectorySlash Off to turn that behaviour off, but it is generally NOT a good idea to do that, unless you have VERY good and valid reasons to do so.

    However, having said that, what you’ve described in your question can be handled by mod_rewrite alone. First, you need to check if the requested resource is a directory. It needs to be a physical directory inside your DocumentRoot.

    RewriteCond   %{DOCUMENT_ROOT}%{REQUEST_URI}  -d
    

    It is vitally important to also apply %{DOCUMENT_ROOT}, otherwise the directory check won’t work.


    • ‘-d’ (is directory)

      Treats the TestString as a pathname and tests whether or not it exists, and is a directory.


    Second, you need to ignore all requests to directories that actually do have a trailing slash.

    RewriteCond   %{REQUEST_URI}                  !/$
    

    Now you’ve filtered down to just the resources you want to redirect to another domain: directories without a trailing slash. Everything else (directories with trailing slashes, images, etc.) is not even in the game at this point. Time for the actual redirect.

    RewriteRule   ^   http://other.com%{REQUEST_URI}/ [redirect=temp,last]
    

    You might want to change your mind later on about the redirection, so you should use temporary redirects (a.k.a. 302 Found) instead of permanent ones (a.k.a. 301 Moved Permanently). The last tells mod_rewrite to stop all further processing.

    And here’s the final product:

    RewriteEngine On
    
    RewriteCond   %{DOCUMENT_ROOT}%{REQUEST_URI}  -d
    RewriteCond   %{REQUEST_URI}                  !/$
    
    RewriteRule   ^   http://other.com%{REQUEST_URI}/ [redirect=temp,last]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

By default JBoss 5.1 writes boot traces to $JBOSS_HOME/server/default/log folder . Is it possible
I know mongrel is the default server for script/server but when I do that
I have a script that connects to SQL Server 2005 default instance. But I'm
I have a DotNetNuke website that by default people use anonymously. When they want
Let's say I have the following workflow with Mercurial: stable (clone on server) default
My server have default php version of 4, so when I run some script
I just want to see error insteas of asp.net showing me default error Server
I am using python default development http server, and it works fine. Error ,The
I am using Websphere7 server and it is shipped with a default IBM version
i want to set the default value in a sql server 2005 datetime field

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.