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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:09:10+00:00 2026-05-21T16:09:10+00:00

I have been having some trouble getting the following to work: <IfModule mod_rewrite.c> DirectoryIndex

  • 0

I have been having some trouble getting the following to work:

<IfModule mod_rewrite.c>
    DirectoryIndex index.php

    Options +FollowSymLinks

    RewriteEngine On

    # If the file is not found in web

    RewriteCond  web/$1 -f [NC] #<-- This line seems to be the problem.
    RewriteRule  ^(.*)$  web/$1  [L]

    # Then rewrite it to index.php

    RewriteRule ^(.*)$ index.php [L,QSA]
</IfModule>

The idea is to check if the file exists in the web directory, and if it doesn’t, route the request to index.php.

The problematic line above seems to pick up the correct URL, but it does not recognize that the file exists.

For example:

http://localhost/img.gif --> /www/web/img.gif
http://localhost/subdir/file.doc --> /www/web/subdir/file.doc
http://localhost/user/add --> /www/index.php
http://localhost/invalidurl --> /www/index.php

However, I cannot get static resources to be served correctly, they are all routed to index.php.

I also want to keep all URLs relative; so I can make this code reusable without editing it.

The following .htaccess gives an Internal Server Error, if I visit img.gif:

<IfModule mod_rewrite.c>
    DirectoryIndex index.php

    Options +FollowSymLinks

    RewriteEngine On

    # If the file is not found in web

    #RewriteCond  web/$1 -f [NC] #<-- This line seems to be the problem.
    RewriteRule  ^(.*)$  web/$1  [L]

    # Then rewrite it to index.php

    #RewriteRule ^(.*)$ index.php [L,QSA]
</IfModule>

This .htaccess redirects to http://localhost/C:/absolute/path/to/web/img.gif, when visiting img.gif:

<IfModule mod_rewrite.c>
    DirectoryIndex index.php

    Options +FollowSymLinks

    RewriteEngine On

    # If the file is not found in web

    #RewriteCond  web/$1 -f [NC] #<-- This line seems to be the problem.
    RewriteRule  ^(.*)$  web/$1  [R]

    # Then rewrite it to index.php

    #RewriteRule ^(.*)$ index.php [L,QSA]
</IfModule>

My conclusion from this would be that it’s getting the path correct, but some weirdness is causing it to do something completely weird (I don’t even know why it has an internal server error – Should be 404 not found).

  • 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-21T16:09:11+00:00Added an answer on May 21, 2026 at 4:09 pm

    Ok I got it:

    When you do a rewrite, then keep in mind that the rewritten URL is called internally.
    So you basically have to reprocess the .htaccess with mostly different values.

    So in your example : http://localhost/img.gif is directed to http://localhost/web/img.gif and then to http://localhost/index.php by the last rule.

    I would try this (replace the last rule by: )

    RewriteCond %{SCRIPT_NAME} !^/web/
    RewriteRule ^(.*)$ index.php [L]
    

    (NB: [QSA] is not needed since you don’t touch the query string, so it is passed as is.)

    Edit : What about

    # If the file is not found in web
    RewriteCond  web/$1 !-f [NC]
    # And we don't ask for /web/something at the beginning (Avoid infinite loops since you'll try to call web/image.gif and we don't want to test /web/web/image.gif and fail to index.php
    RewriteCond %{SCRIPT_NAME} !^/web/
    #Rewrite it to index.php
    RewriteRule  ^(.*)$  index.php  [R,L]
    
    # If the file is found in web 
    RewriteCond  web/$1 -f [NC]
    # And we don't ask for /web/something at the beginning (Avoid infinite loops since you'll try to call web/image.gif and we don't want to test /web/web/image.gif and fail to index.php
    RewriteCond %{SCRIPT_NAME} !^/web/    
    #Then point to web/image.gif
    RewriteRule ^(.*)$ web/$1 [L]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been having some problems trying to get my PHP running. When I
I having trouble in dividing the HTML frames. I have been using the following
I have been having some trouble lately with using custom classes as types. As
I'm having some trouble getting NHV to work with Fluent NHibernate. A unit test
I am having some trouble getting a function to work in internet explorer (7-8).
I have been having some issues with LINQ-To-SQL around memory usage. I'm using it
I am having some trouble getting my application to properly resize the text of
I'm having some trouble getting my Core Data entities to play nice and order
I'm having some trouble getting JSON to store some Javascript as a string value.
Ive been having some trouble using Plot to graph a complicated composite function. I

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.