Jump to content

301 question: htaccess


RyanSF07

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/225329-301-question-htaccess/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.