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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:12:22+00:00 2026-05-27T12:12:22+00:00

I’m trying to better understand mod_rewrite and I’ve come across some differences, which I

  • 0

I’m trying to better understand mod_rewrite and I’ve come across some differences, which I think do the same thing? In this case, no existing files or directories and rewriting to an index.php page.

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .+ - [L]

Do I need the [OR] or can I leave it off?

What are the differences or advantages of the following rules? I’m currently using the first one, but I’ve come across the last four in places like WordPress:

#currently using
RewriteRule ^(.+)$ index\.php?$1 [L]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
  • 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-27T12:12:22+00:00Added an answer on May 27, 2026 at 12:12 pm

    Do I need the [OR] or can I leave it off?

    In this case you need the [OR] because RewriteCond’s are inherently ANDed, and it’s not the case that a request is both a file and a directory (as far as mod_rewrite is concerned).

    RewriteRule ^(.+)$ index\.php?$1 [L]
    

    This rewrites all requests that aren’t for the document root (e.g. http://domain.com/) as a query string for index.php, thus a request for http://domain.com/some/path/file.html gets internally rewritten to index.php?some/path/file.html

    RewriteRule ^index\.php$ - [L]
    

    This is a rule to prevent rewrite looping. The rewrite engine will continue to loop through all the rules until the URI is the same before the rewrite iteration and after (without the query string). If the URI starts with index.php simply stop the current rewrite iteration (what the – does). The rewrite engine sees that the URI before sending it through the rules was index.php and after the rules was index.php, thus the rewrite engine stops and all rewriting is done. This prevents mod_rewrite from rewriting things to index.php?index.php which the first rule would do upon the 2nd pass through the rewrite engine if it isn’t for this rule.

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    

    This is the catch-all. If the first rule never gets applied, and the request isn’t for an existing file or directory, send the request to index.php. Though in this case, it looks like this rule will never get applied.


    EDIT:

    is there a way to ignore a certain rule if a condition is true? For example, http://www.domain.com/some/path > index.php?some/path, but if the URI is http://www.domain.com/this/path > no rewrite?

    You’d have to add 2 conditions, one that checks to make sure the requested host isn’t “www.domain.com” and one to check that the URI isn’t “/this/path”:

    RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com$  [NC,OR]
    RewriteCond %{REQUEST_URI} !^/some/path 
    

    The [NC] indicates that the condition’s match should ignore case, so when someone enters the URL http://WWW.domain.com/ in their address bar, it will match (or in this case, not match). The second condition matches when the URI starts with “/some/path”, which means requests for http://domain.com/some/path/file.html will match and NOT get rewritten. If you want to match exactly “/some/path”, then the regular expression needs to be !^/some/path$.

    Why not use [OR] in the final block between !-f and !-d?

    This is the logical negation of -f OR -d: “if the file exists, don’t rewrite, OR if the directory exists, don’t rewrite” turns into “if the file doesn’t exist, AND if the directory doesn’t exist, then rewrite”

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.