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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:13:46+00:00 2026-06-13T11:13:46+00:00

I have a .htaccess file in my htdocs/MVC/ folder which looks like this RewriteEngine

  • 0

I have a .htaccess file in my htdocs/MVC/ folder which looks like this

RewriteEngine On

# if its already been rewritten to the specific folder
RewriteCond %{REQUEST_URI} ^/MVC/public/img/(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^/MVC/public/index.php$
# skip next two rules
RewriteRule .? - [S=2]

# rewrite image requests
RewriteRule (.*\.(jpg|png|gif))$ public/img/$1 [L]
# rewrite all other requests to the front controller index.php
RewriteRule (.*) public/index.php?url=$1 [QSA,L]

What I want to achieve is all image requests going to the folder MVC/public/img all other requests going to the front controller index.php in the folder MVC/public. Is this the best way to set up those rules and prevent mod_rewrite to loop?

  • 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-13T11:13:47+00:00Added an answer on June 13, 2026 at 11:13 am

    Using the S flag to skip is fine but the downside is:

    1. it’s a little harder to read (if someone else is looking at it)
    2. if you need to append new rules, you need to check the way it skips
    3. if your rules gets increasingly more complex, it gets increasingly harder to maintain the correct skipping

    Other possible ways of preventing looping:

    RewriteCond %{ENV:REDIRECT_STATUS} 200
    RewriteRule ^ - [L]
    

    Putting this at the very top of your rules will instantly stop rewriting altogether if a rule was applied (or a mod_alias redirect was applied) in the previous loop.

    So it’ll look like this:

    RewriteCond %{ENV:REDIRECT_STATUS} 200
    RewriteRule ^ - [L]
    
    # rewrite image requests
    RewriteRule (.*\.(jpg|png|gif))$ public/img/$1 [L]
    # rewrite all other requests to the front controller index.php
    RewriteRule (.*) public/index.php?url=$1 [QSA,L]
    

    Pros: You never have to worry about looping, because the 2nd time around instantly ends with the ENV check
    Cons: If you ever happen to need to create a rule that loops, this method will prevent it from ever working

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

Sidebar

Related Questions

I have a .htaccess file that looks like this: SetEnv APPLICATION_ENV development RewriteEngine On
Ok, so I have this .htaccess file that contains this <IfModule mod_rewrite.c> RewriteEngine On
I have this .htaccess file but I would like it to only do this
I have a .htaccess redirect for non www like this: RewriteEngine on RewriteCond %{HTTP_HOST}
I have an .htaccess file set up like so: RewriteEngine on RewriteRule ^home/ /member.php
I have an htaccess file which begins with the regular stuff: RewriteEngine on RewriteBase
I have this htaccess file: RewriteEngine On RewriteRule ^([a-zA-Z0-9]+:/.)$ result.php?u=$1 RewriteRule ^([a-zA-Z0-9]+:/.)/$ result.php?u=$1 And
I have a htaccess file in a sub folder like so: /subfolder/.htaccess In the
I have htaccess file and this is in it: RewriteEngine On Options +FollowSymlinks RewriteBase
i have .htaccess file which includes below code. RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond

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.