views:

386

answers:

2

Hey gang,

Bear with me as I try to learn more about .htaccess redirect rules - I'm a UI guy by profession and I'm doing my best to enhance my coding skills languages other than HTML/CSS/PHP, etc

So, what I have is an index.php file that contains a menu - pretty simple. If Javascript is enabled on the users computer then forms are shown below the menu using simple jQuery goodies, with each link having a 'return false;' applied.

What I am trying to do is make the page accessible with JS turned off, so instead of redirecting the user to a different page, I would like to use POST or GET variables from each link, to show the various forms.. within the same index.php file - but have the URL reflect the menu choice

Here is an example using menu items named - Home, About, Form1 and Form2:

With JS on, clicking on of the above example buttons simply slides the form or containing the data down onto the page.

With JS off, if the user clicks the 'About' link, I would like to rewrite the URL to be http://domain.com/about - but keep the user on the index.php page (since it is the only page) and be able to use POST or GET variable to show the using PHP.

So, accessing http://domain.com/index.php?page=about would show http://domain.com/about in the URL but pass the GET variable 'page' to the index.php file.

Hope that makes sense.. and I'm sure there are many ways to accomplish this, so if you have ideas of how to improve on it, by all means, I'd love to hear it !

Thanks again Revive

+3  A: 

mod_rewrite:

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /index.php?page=$1 [L]
Ignacio Vazquez-Abrams
I tried this... but now the CSS files wont load.. any thoughts?Here is another I was tinkering with:RewriteEngine OnRewriteBase /RewriteCond %{REQUEST_FILENAME} !-f # ignoring any existing filesRewriteCond %{REQUEST_FILENAME} !-d # ignoring any existing directoriesRewriteRule . /index.php [L]
revive
Yes, I did mean `%(REQUEST_FILENAME}`. Fixed.
Ignacio Vazquez-Abrams
gotcha.. ok, I tested it with the changes and no dice.I was using this URL: http://localhost/proj/name/index.php?page=test3and tried:http://localhost/proj/name/test3but it says:The requested URL /index.php was not found on this server.Thoughts?
revive
Change the `RewriteBase` directive or the right-hand side of the `RewriteRule` directive.
Ignacio Vazquez-Abrams
@Ignacio - change them to what?
revive
To `/proj/name` and/or `/proj/name/index.php?page=$1` respectively.
Ignacio Vazquez-Abrams
- scratch that.. I setup a Vhost in MAMP pro and it worked after commenting out the RewriteBase:D
revive
I cant choose this answer because of a rep score lower than 15 - can someone give Ignacio credit for this ???? :D
revive
THIS SOLUTION WORKED GREAT - but I cannot choose this as an answer becuase Stack Overflow is requiring me to have a score of 15 before I can vote!! LAME ! Anyway, Thanks Ignacio for the solution
revive
A: 

Hello, I am using htaccess to redirect people from a domain that is registered on my host to a folder. Ex: the user type www.my2nddomain.com and I redirect them to www.my1stdomain.com/folder. But I wanted to show the domain the user typed instead of the address with the folder on it. How do I do it? Thanks in advance!

Ricardo