mod_rewrite and hyperlinks
I'm trying to get my head around mod_rewrite and friendly URLS.
OK, on a very basic level I have the following rule:
RewriteRule ^register$ register.php [L]
This allows me to browse to www.mydomain.com/register
The hyperlink within my pages shows register.php. Do I have to manually change my links to register?
Esentiallly开发者_StackOverflow社区, I do not want the .php extension on any of my links.
Thanks!!
Yes, you must manually change the hyperlinks (or use your favourite search-and-replace tool). mod_rewrite
can't do this for you; it can only rewrite incoming requests, not outgoing HTML.
Yes, you'll need to change the URL in your code if that's not what you want to show up in the address bar.
Just an addition:
Note that RewriteRule ^(.*)$ /$1.php
rewrites all files for you which saves you typing a lot of rules ;) Offcourse you can add more validation to it by using something like RewriteRule ^(.*)$ /index.php?pageId=$1
.
精彩评论