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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.