Reputation: 2469
I am looking to create a few rewrite rules. Here are the types of urls I want to change.
http://www.mysite.com/profile/kwelch
change to profile.php?username=kwelch
Here is the line I have for that:
RewriteRule ^profile/([^/.]+)/?$ profile.php?username=$1
I am also looking to rewrite all ages to add the .php
to any page.
RewriteRule ^(.*)$ $1.php [L, QSA]
I would like to have these work together and also add more that have the same logic as the first.
Other urls:
http://www.mysite.com/wof/vote
change to vote.php?type=wof
http://www.mysite.com/wof/nominate
change to nominate.php?type=nominate
I would like to add more to the url such as user id if possible.
I have attempted to add my two lines together and they work beautifully seperately but the page errors and shows a 500 error.
I appreciate the help.
Upvotes: 0
Views: 686
Reputation: 145482
It's foremost a matter of order: Everything You Ever Wanted to Know about Mod_Rewrite Rules but Were Afraid to Ask?
Your rule to add the extension should be the first, and slightly adapted however:
RewriteCond %{SCRIPT_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L,QSA]
This ensures it only rewrites requests which really exist as .php script. An assertion in the RewriteRule like (?<!\.php)
might have the same effect. (Much simpler would be resorting to MultiViews
in place of this RewriteRule.)
And lastly you might have luck with adding [L]
to each further rule. This prevents loops in the rewrite engine, which I suspect is what your unspecified error is about.
Upvotes: 1