6

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

1 Answer 1

9

mod_rewrite:

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /index.php?page=$1 [L]
Sign up to request clarification or add additional context in comments.

10 Comments

I tried this... but now the CSS files wont load.. any thoughts? Here is another I was tinkering with: RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f # ignoring any existing files RewriteCond %{REQUEST_FILENAME} !-d # ignoring any existing directories RewriteRule . /index.php [L]
Yes, I did mean %(REQUEST_FILENAME}. Fixed.
gotcha.. ok, I tested it with the changes and no dice. I was using this URL: localhost/proj/name/index.php?page=test3 and tried: localhost/proj/name/test3 but it says: The requested URL /index.php was not found on this server. Thoughts?
Change the RewriteBase directive or the right-hand side of the RewriteRule directive.
@Ignacio - change them to what?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.