lost305 Posted June 13, 2008 Share Posted June 13, 2008 This must be so easy but I can't figure it out. how do i redirect modules.php?name=News&file=article&sid=x to contenido/node/x I tried... # Enable rewrite engine Options +FollowSymLinks RewriteEngine on RewriteRule ^modules.php?name=News&file=article&sid=([0-9]+)$ contenido/node/$1 But that doesn't work. I'm very new to this and by what I've displayed you can tell I have no idea what I'm doing, but I bet it's so easy, right? Can you explain please? ??? Thank you for your time. Any help will be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/110011-sooooooooooo-easy-right/ Share on other sites More sharing options...
lost305 Posted June 13, 2008 Author Share Posted June 13, 2008 Well I found this on another website and changed what I thought might work and voila! <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{QUERY_STRING} ^name=News&file=article&sid=(.*)$ RewriteRule ^modules.php$ /contenido/node/%1? [R=301,L] </IfModule> In case anyone has the same problem. Funy I read somewhere else that I had to put a $1 instead of a %1 Also read to end the line with $ instead of ? So confusing but I got it to work. If anyone can tell me how to do it better I would love you for ever ) Quote Link to comment https://forums.phpfreaks.com/topic/110011-sooooooooooo-easy-right/#findComment-564828 Share on other sites More sharing options...
corbin Posted June 14, 2008 Share Posted June 14, 2008 Well... Err.... That will work, but if you want to know what was wrong with your first try, I shall explain: RewriteRule takes a regular expression parameter, and in regular expressions, ? is a quantifier meant to mean optional. For example ^Am I corbin?$ Would match 'Am I corbi' and 'Am I corbin,' not 'Am I corbin?' ^s?he Would match anything starting with either she or he for another example. So, to make the ? mean literally a question mark, you must escape it. \ can be used (in this context) to escape things. # Enable rewrite engine Options +FollowSymLinks RewriteEngine on RewriteRule ^modules\.php\?name=News&file=article&sid=([0-9]+)$ contenido/node/$1 Oh! I forgot until now to mention '.' . means any character. (So, that would match modulesaphp, modules.php, modulesb.php so on). Quote Link to comment https://forums.phpfreaks.com/topic/110011-sooooooooooo-easy-right/#findComment-565447 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.