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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:51:26+00:00 2026-05-26T20:51:26+00:00

I have all my rewrite rules setup and working in .htaccess but I need

  • 0

I have all my rewrite rules setup and working in .htaccess but I need to redirect all unmatched rules to a common place.

Here are the rules:

# add trailing slash    
RewriteCond %{DOCUMENT_ROOT} -d
RewriteRule ^([^.]*[^/])$ $1/ [R]

# redirect directories to old site if it exists    
RewriteCond %{DOCUMENT_ROOT}/old_site/$0 -d
RewriteRule ^(.*) old_site/$1 [NC,QSA,L]

#redirect files to old site if they exist
RewriteCond %{DOCUMENT_ROOT}/old_site/$0 -f
RewriteRule ^(.*) old_site/$1 [NC,QSA,L]

This works great, but trying to redirect the rest of the traffic (all unmatched rules) to index.php just over writes all the rules above:

RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

How can I insure this part only gets executed if nothing else (I guess except the trailing slash part) was matched?

EDIT:
As per @Jon Lin I’ve changed the last three lines to

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php

Which now works for everything but directories that don’t end in a slash. I can’t put [L] on the first rule because I need it to re-write further to a different directory.

  • 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-26T20:51:26+00:00Added an answer on May 26, 2026 at 8:51 pm

    That rule is never going to get applied because the %{REQUEST_FILENAME} is never going to be a directory and not a directory at the same time. If you want existing directories and files to not get rewritten (like if you link to an image), then include these conditions:

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    

    The rule you have is fine. But you may want to include a [L] at the end of it.

    Also, the first rule you have, you are checking if the document root is a directory (it should), that means that rule will always be applied, which means /index.php is going to get rewritten to /index.php/. I think you may be looking for %{REQUEST_FILENAME} instead of %{DOCUMENT_ROOT}.

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

Sidebar

Related Questions

I have 8 lines of rewrite rules in my .htaccess file. I need to
I have an htaccess redirect set up for a bunch of domains to all
I have an htaccess rewrite setup in my PHP application to route files via
I have set up a few rules based on other questions but now my
I have successfully created rewrite rules to handle URLs like http://example.com/xyz http://example.com/xyz/ http://example.com/xyz/abc http://example.com/xyz/abc/
I have a CI application that uses .htaccess for URL routing. My basic setup
I have problems with static files url rewriting in current .htaccess setup on Apache2.
Hey all, I have the following setup in my webroot: /issues (Trac install) /myapp
I have a web.config rewrite rule specified to move all traffic to https. The
I have a website that employs a generic mod_rewrite rule to push all requests

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.