I have a single page website that changes content based on variables passed through the URL with PHP.
For instance, my url displays as
www.mysite.com/index.php?section=home
www.mysite.com/index.php?section=about-us
so forth and so on, depending upon which link you click in the main navigation.
I want the urls to read as www.mysite.com/home or www.mysite.com/about-us.
My mod-rewrite feature is enabled because before I made this a one page site, it was functioning correctly.
I’ve tried this…
RewriteEngine on
RewriteBase /
RewriteRule ^home/?$ index.php?section=$1 [NC,L]
I’ve tried every suggestion I found on Google and on StackOverflow, nothing is working.
Any help would be appreciated!
I have an
.htaccessfor exactly the same purpose, and it’s working beautifully. My code is below.Naturally, if
index.phpisn’t your main PHP file, replace that with what is. Also, replace?idwith?sectionif your example code is what your using.What the
[^/\.]+means is sayingI need you to find text that contains anything but a period (.) or a forward slash (/), and there has to be at least one character in it.For an example, go to the website I’m using it on, Northside Aikido.
If you have any questions, please feel free to ask.
EDIT
Note, this code won’t turn
http://www.example.com/index.php?section=homeintohttp://www.example.com/homeautomagically, it’ll just mean that the latter link works like the former. If you want it to automatically replace it, you’ll need more code than one line.