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

  • Home
  • SEARCH
  • 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 9277643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:09:31+00:00 2026-06-18T17:09:31+00:00

My goal is to redirect users from these paths: /foo/index.php /foo/ To /index And

  • 0

My goal is to redirect users from these paths:

/foo/index.php
/foo/

To

/index

And have /index load the original content from /foo/index.php.

Is this possible in .htaccess?

So far I’ve tried:

RewriteRule ^foo/(index\.php)?$ /index [R=301,QSA,L]
RewriteRule ^index$ /foo/index.php [QSA,L]

But this gets into an infinite redirection loop. I thought adding a RewriteCond for the URI would help, but from the docs:

Note: Conditions are being processed after the pattern of the RewriteRule has matched.

So apparently RewriteCond won’t be of much use in my use case.

Looking through the Rewrite Flags docs, the S flag seems to be what I’m looking for:

This flag forces the rewriting engine to skip the next num rules in sequence, if the current rule matches. Use this to make pseudo if-then-else constructs: The last rule of the then-clause becomes skip=N, where N is the number of rules in the else-clause.

So I’ve tried:

RewriteRule ^index$ /foo/index.php [QSA,L,S=1]
RewriteRule ^foo/(index\.php)?$ /index [R=301,QSA,L]

Though, as I have the L flag, the S flag seems a little redundant. Nevertheless, the logic seems correct in my view, though this is still in an infinite redirection loop.

Right now I’m using an workaround with PHP. First, Apache internally rewrites the new URL to the old one and then in the PHP I check if the $_SERVER['REQUEST_URI'] matches the new format in the beginning of the script, otherwise ensue a 301 redirect to the new URL.

Though, I’d like to know whether this possible to do with .htaccess solely? Or if anyone can explain how/why I’m getting an infinite loop with the rewrite rules above I will be grateful.

  • 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-18T17:09:33+00:00Added an answer on June 18, 2026 at 5:09 pm

    The trouble is that the rules are in a .htaccess file, and as docs say, this file is reparsed after every rewite loop, letst it might have been applicable to a .htaccess in a different directory. Thus your L flags are all in vain.

    I have looked around, and if you really cannot place your rewrite rules in the main apache config, I can offer the following kludge: because the Server-Variables THE_REQUEST is not updated between the rewrite runs, one can conclude the “browser visible URL” from there and prevent rewriting in that case:

    # external redirect to /index (unless browser already shows /index plus query params)
    RewriteCond %{THE_REQUEST} !^\w+\ /index(\?.*)?\ HTTP/1..$
    RewriteRule ^foo/(index\.php)?$ /index [R=301,QSA,L]
    
    # internal redirect for /index
    RewriteRule ^index$ /foo/index.php [QSA,L]
    

    I thought there is also another variable that remains unchanged, but right now I cannot find it. Maybe someone else ?

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

Sidebar

Related Questions

My goal is to redirect my website to (/2012/index.php) ONLY IF the user goes
I have a default.aspx page like this with the goal of redirecting differently based
This is my first time developing a rails app from scratch. The goal of
I have Users and each user sets a Goal. So a goal belongs_to a
The goal is to make redirect from /Swiss+Military/something.. to /Swiss+Military+Hanowa/something.. I've tried: RewriteCond %{REQUEST_URI}
This may be a fairly simple question, but my goal here is to redirect
Goal: Produce an Excel document with information from 3 associated models that is similar
I have the following remote form_tag, whose goal is to POST the following params:
If I had a user resource, I might have a page like /users/1. What
I have a web page, let's call it main.php which displays an image of

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.