Forum Moderators: phranque
I'm updating a website I did some time ago and I really want to simplify the URL's and make them Search Engine friendly. This is the code I'm using on the .htaccess
Options +FollowSymlinks
RewriteEngine OnRewriteRule ^(.*)\$ http://mysite.com/teste.php?do=$1 [NC]
I want it to 'transform' mysite.com/gallery on the browser to mysite.com/teste.php?do=gallery on the server for example.
But when I try going there it won't show me the gallery but instead it shows me a 404 error (yes, teste.php exists on the root directory).
What's wrong with my code?
P.S. I have applications such as Joomla and wordpress installed using friendly url's on the same server so it probably isn't an Apache error.
Thanks in advance for any answers ;)
As coded above, your rule actually produces a 302 redirect TO a parameter-based URL. I suspect you needed an internal rewrite, not a redirect here. Luckily, this question comes up every day here, so there are plenty of prior threads.
As coded, your rule affects all URL requests: not just those for HTML pages, but also robots.txt, all images and CSS and JS files too. That is probably also not what you want.
You have to change the links ON your pages to use the URLs that you want users to 'see' and 'use'. It is those links that define URLs. You then use a rewrite to connect those URL requests to the internal files inside the server.As coded above, your rule actually produces a 302 redirect TO a parameter-based URL. I suspect you needed an internal rewrite, not a redirect here. Luckily, this question comes up every day here, so there are plenty of prior threads.
As coded, your rule affects all URL requests: not just those for HTML pages, but also robots.txt, all images and CSS and JS files too. That is probably also not what you want.
I also took the $ but it didn't worked.
I feel like this is really complicating all this stuff that should be simple so now I changed it to:
RewriteRule ^gallery/([0-9]+) http://example.com/teste.php?do=gallery¶m1=$1 [NC]
RewriteRule ^gallery http://example.com/teste.php?do=gallery [NC]
But now it redirects me to teste.php?do=blahblah instead of processing it on the server
[edited by: jdMorgan at 3:22 am (utc) on June 23, 2009]
[edit reason] example.com [/edit]