Search code examples
.htaccessurlargumentsurl-rewritinghref

How can I append a string to an incoming url when someone visits the root of my website?


I'm trying to get the string /index.php?page=home behind the adress in de adressbar when people visit the root of my site.

I tried rewrite rules in .htaccess but it redirects to the .php without any css etc. Like this:

RewriteRule (.*) index.php?page=home

I tried javascript rewrite but it reloads the page Like this:

window.location.href = "/index.html?page=home"

My page already takes the arguments and follow a javascript function, but I would like to just simply add something to the current URL in the bar, without reloading or doing anything else.

Any ideas?


Solution

  • By the sound of it, you'll have to use the hash to do what you want. You can go from http://example.com/#home to http://example.com/#contact without reloading the page, but you cannot go from http://example.com/index.php?page=home to http://example.com/index.php?page=contact without reloading the page.

    You can set and read from the hash using window.location.hash in javascript.