Forum Moderators: phranque
I would like to get the urls to change to something like this for the benefit of my users. This is what I came up with:
RewriteEngine on
RewriteBase /
RewriteRule ^user.php?user=(.*)$ /$1 [R]
However its not working and I really have no clue what I am missing. Any help would be greatly appreciated.
[edited by: jdMorgan at 1:58 am (utc) on Sep. 19, 2007]
[edit reason] example.com [/edit]
If you want the URLs to change, you need to change your on-page links, which define the URLs on the Web, to the /username format.
Having done so, you then rewrite those /username URLs, when requested from your server, back to the /user.php?user=username format needed to invoke your script. mod_rewrite works after a request is received by your server, but before any content is served or any scripts are invoked. It cannot modify the pages output by your server.
More detail here [webmasterworld.com].
Jim
Im still not sure what I need to do though. When you say "change your on-page links" do you just mean that I should goto the url http://www.example.com/username instead of looking for a redirect from the old url? Or do you mean that I need to change the user.php file that I am trying to change?
Having done that, you can take a third optional step -- redirect any direct requests for the old URLs to the corresponding new ones. But this step is tricky, optional, and not a part of the required solution.
Jim
Additionally, you will need an external redirect such that if someone requests the "dynamic" URL, the server does NOT serve this Duplicate Content, but instead forces the browser to make a new request for the correct URL.
Some clues are in: [webmasterworld.com...]
g1smd Your explanation really cleared things up for me, and the thread you linked to was a great help.
I have one question now that its working though. I used the following to rewrite:
RewriteRule ^([^/\.]+)/$ /user.php?user=$1
That seems to work perfect, although I know seeing I have "([^/\.]+)/" that the content will only display when it is followed by a /. So my question is seeing that the ([^/\.]+) is referring to a user name, which there will be many of. Should I also add a rule which will cover this in the case of a type in for instance where the user does not add the "/"? Will it matter if I add the second rule?
Thanks again!
RewriteRule ^([^/.]+)/?$ /user.php?user=$1 [L]
RewriteRule ^([a-z0-9_\-]+)/?$ /user.php?user=$1 [NC,L]