Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Is it possible to make the URL index.php?view=something back into /something?

share|improve this question

marked as duplicate by MadHatter, womble Sep 24 at 10:07

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Yes. The rewrite rules can manipulate any data it's given. You can't recover data lost in a previous rewrite (usually). – Chris S Dec 27 '10 at 1:49

1 Answer 1

RewriteCond %{QUERY_STRING} [&?]view=([^&]*)
RewriteRule index.php$ /%1

Note that, if you're not careful, a crafty attacker might be able to abuse this; for example, by generating arbitrary URIs by passing parameters to "view". Appropriate precautions should be taken.

Also, you might want to append an [L], [R], or [R=301] to the RewriteRule (or a combination thereof), depending on your exact intent.

share|improve this answer
As long as the URL is rewritten to the same server, how can this technique be abused? (curious because this is how I do it on my website). – sirlancelot Dec 27 '10 at 2:23
One example off the top of my head: let's say you wanted to let rewritten index.php's be deeper than "/", so you had a rule like RewriteRule index.php$ %1 [L,R]. Imagine if I gave you the URI‌​m—what happens? – BMDan Dec 27 '10 at 2:53
haha the views are already set. – Kyle Dec 27 '10 at 22:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.