mod-rewrite forwarding without changing URL

13,339

Solution 1

Try the following:

RewriteEngine On
RewriteRule ^index\.html$ /index.php?pageID=Forside [L]

I think this may help you to resolve your problem.

Solution 2

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^index.html$  /index.php?pageID=Forside [L]

This will do the redirect for you whilst showing index.html in the browser window.

Share:
13,339
Severin
Author by

Severin

Rails developer specializing in WebScraping, using: HTML/XML/YAML XPath Regexp Ruby on Rails PostgreSQL

Updated on June 04, 2022

Comments

  • Severin
    Severin almost 2 years

    I have a small problem with my Apache configuration when creating "pretty" URLs. I've got it to the stage where typing (or linkig for that matter) to

    index.html

    forwards you to

    index.php?pageID=Forside

    that is exactly what I want. But how can I get index.html to stay in the address bar of the browser? Right now it forwards and changes the URL to the original one.

    Here my .htaccess:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} index\.html
    RewriteRule .* http://www.radoor-designs.dk/index.php?pageID=Forside [L]
    

    And before someone comments on it: Options +FollowSymLinks is missing since it triggers an error 500 on a one.com webhotel.

    Thanks in advance!

  • Severin
    Severin over 11 years
    When you go on radoor-designs.dk/index.html it opens the index as it should, but changes the URL you typed in into the original -> radoor-designs.dk/index.php?pageID=Forside The whole point of the rewrite was to have a URL that looks good and is SEO friendly - which means that it should not contain ?pageID=something&id=4
  • Neo
    Neo over 11 years
    is there a difference between index.php and index.php?pageID=Forside?
  • Severin
    Severin over 11 years
    No - that is the point of it. I want index.html silently linked to the one with the PHP variable. "Invisible" for the user if you want. The browser window should show the content of index.php?pageID=something while the address bar still shows index.html
  • maganap
    maganap about 9 years
    To explain why this happens, if you start the destination argument in the RewriteRule with http:// it will cause a Redirection (it's just like using the [R] flag, also called an External Redirect). This will cause the browser to make a new request, hence changing the URL showed in the address bar. To avoid a redirection, and actually "map" the URL (internal mapping, user won't see a change in the address bar), don't use [R], and the destination argument in the RewriteRule should point to a relative destination.
  • B T
    B T almost 8 years
    Why do you think it might resolve the problem? This doesn't explain anything
  • Gerardlamo
    Gerardlamo about 7 years
    This doesn't work for me, as the new url is changed to /index.php?pageID=Forside