Apache rewrite rule and keep the url unchanged?

5,155

Solution 1

What Lairsdragon said is correct. However, if you have more than one rewrite rule in your config, you will want to add the [L] flag to the end in order to prevent other rules from being applied.

Solution 2

The Pattern in the RewriteRule is wrong. A

RewriteRule ^/ar$       /index2.html

should to exactly what you want: It rewrites the /ar to index2.html without telling the web browser about the redirection.

Share:
5,155

Related videos on Youtube

Alaa Alomari
Author by

Alaa Alomari

Updated on September 18, 2022

Comments

  • Alaa Alomari
    Alaa Alomari over 1 year

    I have this rewrite rule

    RewriteRule ^ar$       /index2.html
    

    but i need to keep the url in the address bar unchanged after the redirect.
    ie. if the user typed http://mydomain.com/ar i need to redirect him to /index2.html but keep the url as is.
    any idea of how to do so??
    Thanks for your help

  • Alaa Alomari
    Alaa Alomari about 13 years
    ok... what shall it be... i tried too many flags like L,NC,R=301, R and too many others, but didn't get it as i want... so what shall it be??
  • Alaa Alomari
    Alaa Alomari about 13 years
    this is what i know!! it is supposed to keep the url unchanged if you didn't provide any rewrite flag!! but this didn't work with me!! any idea??
  • edwin
    edwin about 13 years
    Could it be that you dont really redirect to a static file? If another apache module is involved like mod_proxy, mod_jk etc this ma lead to an external rewrite via HTTP code 302
  • matthew
    matthew about 13 years
    @Alaa If you remove that rule completely do you still get the redirect? If so you probably have another rule or directive that is being applied first.