RyanSF07 Posted January 22, 2011 Share Posted January 22, 2011 Hello, I'd like to permanently redirect: www.site.com/this_page.php?id=this number to: www.site.com/this_New_page.php?id=this number I want to keep this part ?id=this-number-and-or-anything-else as a variable or something and stick it on the end of a new page. Does that make sense? The closest I've found on google is: RewriteEngine on RewriteCond %{QUERY_STRING} ^id=13$ RewriteRule ^/page.php$ http://www.example.com/newname.htm? [L,R=301] but I think that would mean I'd have to have an id=# for every id in the database -- pointing it to a different page. How do you say, "save everything after .php -- and stick on the end of the this Newpage.php" ? If you understand what I'm trying to do and could point me in the write direction -- that'd be great. I understand I can do this with PHP too, but htaccess is the most efficient way to redirect. (Moderators please move or delete this post if it's outside the scope of this forum. I appreciate the help I get here, but understand this isn't specifically a php question and don't mean to rock the boat.) thanks, Ryan Quote Link to comment https://forums.phpfreaks.com/topic/225329-301-question-htaccess/ Share on other sites More sharing options...
merylvingien Posted January 22, 2011 Share Posted January 22, 2011 Surely its just a simple 301 redirect? redirect 301 /this_page.php?id= http://www.site.com/this_New_page.php?id= Quote Link to comment https://forums.phpfreaks.com/topic/225329-301-question-htaccess/#findComment-1163623 Share on other sites More sharing options...
DavidAM Posted January 22, 2011 Share Posted January 22, 2011 I don't think that the query string can be used as a condition of the redirect or rewriterule directives. I think you have to use the RewriteCond to test the query string and then use a rewrite rule to do the redirect. Someone correct me if I'm wrong. If you want to redirect ALL requests for this_page.php - regardless of what is in the query string: RewriteRule ^this_page.php$ /this_New_page.php [R=301,L] If you want to redirect ONLY requests whose query string STARTS with "id=": RewriteCond %{QUERY_STRING} ^id= RewriteRule ^this_page.php$ /this_New_page.php [R=301,L] If you have more complex conditions, post them, and be very specific. The code above will NOT redirect this_page.php?mode=delete&id=4 but would redirect this_page.php?id=4&mode=delete Quote Link to comment https://forums.phpfreaks.com/topic/225329-301-question-htaccess/#findComment-1163630 Share on other sites More sharing options...
merylvingien Posted January 22, 2011 Share Posted January 22, 2011 ive just checked one of my sites and i have a working redirect setup as i posted above and it works ok. Quote Link to comment https://forums.phpfreaks.com/topic/225329-301-question-htaccess/#findComment-1163656 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.