Current location: Hot Scripts Forums » Other Discussions » Web Servers » [SOLVED] .htaccess 301 redirect

[SOLVED] .htaccess 301 redirect

Reply
  #1  
Old 02-29-08, 10:18 AM
snaip's Avatar
snaip snaip is offline
iNET Interactive
 
Join Date: Nov 2003
Posts: 955
Thanks: 1
Thanked 2 Times in 2 Posts
[SOLVED] .htaccess 301 redirect

Hi members of PT,

I need some .htaccess help. I need to do a 301 redirect and map this:
Code:
http://temp.mydomain.com/index.php?module=ContentExpress&func=display&ceid=182
to
http://temp.mydomain.com/ce.php?id=182
Now, this only needs to be redirected if and only if the variable contains the term 'ContentExpress'. It shouldn't redirect for any other modules.

I tried the following:

Code:
Options +FollowSymlinks
RewriteEngine on
RedirectMatch 301 /index.php?module=ContentExpress&func=display&ceid=(.*) /ce.php?id=$1
but that didn't work.

Can someone please assist?
__________________
Regards,
Ahmad Permessur
Team HotScripts
Reply With Quote
  #2  
Old 02-29-08, 10:19 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 7,536
Thanks: 5
Thanked 20 Times in 18 Posts
Try replacing the last line of your code with:
Code:
RedirectMatch 301 /index\.php\?module=ContentExpress&func=display&ceid=(.*) /ce.php?id=$1
The question mark and the dot need to be escaped.
Reply With Quote
  #3  
Old 02-29-08, 10:26 AM
snaip's Avatar
snaip snaip is offline
iNET Interactive
 
Join Date: Nov 2003
Posts: 955
Thanks: 1
Thanked 2 Times in 2 Posts
Nico,

Thanks; I'm afraid, this didn't work!
__________________
Regards,
Ahmad Permessur
Team HotScripts
Reply With Quote
  #4  
Old 03-01-08, 09:00 AM
curbview.com's Avatar
curbview.com curbview.com is offline
Junior Code Guru
 
Join Date: May 2006
Posts: 555
Thanks: 0
Thanked 0 Times in 0 Posts
Snaip, I hacked this up and tested this for you. (I work with .htaccess a lot)

Code:
RedirectMatch 301 (.*ContentExpress)(.*)(id=[0-9]+)$ http://temp.mydomain.com/ce.php?$3
__________________
Whatever you decide, you should make sure best security methods are used and practiced. Should you really need more help, PM me.
Reply With Quote
  #5  
Old 03-01-08, 09:16 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 7,536
Thanks: 5
Thanked 20 Times in 18 Posts
Turns out there was a PHP error, which didn't show up 'cause display_errors was disabled in php.ini.

It's working now. Sorry, I should have informed you before.
Reply With Quote
  #6  
Old 03-01-08, 09:50 AM
curbview.com's Avatar
curbview.com curbview.com is offline
Junior Code Guru
 
Join Date: May 2006
Posts: 555
Thanks: 0
Thanked 0 Times in 0 Posts
Nico,

Don't mean to interject here, but looking over the code you posted for Snaip, using (.*) at the end opens the redirect to way too much. For example, your code would allow the following redirect:

1) .../.../any code your heart desires.
2) Any Alphanumeric characters

The code below places restraint on the actual redirect by it having to end with (id + numbers 0-9) and also allows different URL's by including the (.*) in between.

This eliminates such
Code:
RedirectMatch 301 (.*ContentExpress)(.*)(id=[0-9]+)$ http://temp.mydomain.com/ce.php?$3
__________________
Whatever you decide, you should make sure best security methods are used and practiced. Should you really need more help, PM me.
Reply With Quote
  #7  
Old 03-01-08, 10:08 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 7,536
Thanks: 5
Thanked 20 Times in 18 Posts
Yes, you're absolutely right. Usually I take better care of this, I guess I missed it 'cause I just copied and pasted Snaip's original code, and modified it from there. (I replied one minute after he posted his question, so I didn't take too much time to look carefully in all details.)

Also, allowing other characters doesn't necessarily mean it's insecure. It also depends on the PHP script.

Anyway, I'll take better care of it next time.
Reply With Quote
  #8  
Old 03-06-08, 04:06 PM
freerange freerange is offline
New Member
 
Join Date: Mar 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Same Problem, Still

Hi,
This is a great forum, thanks for your time.
I have the same need as this poster, but the various solutions don't seem to be working. Other redirects are working without any problems, just these with the ? being passed into them.

Source string from search engine link:
http://www.foobar.com/mm5/merchant.mvc?Screen=PROD&Product_Code=ABC123

Desired redirected string:
http://www.foobar.com/ABC123

Here is what I have tried...
DirectoryIndex home.php index.php
Options +FollowSymLinks
RewriteEngine On
RedirectMatch 301 (.*mm5)(.*Product_Code=)(.*)$ http://www.foobar.com/$3

It matches until I request anything to match after the ? in the original string. Then it just hits my page not found redirect to the homepage.

Any thoughts as to what I am doing wrong?

Thanks! - Derrick

Last edited by freerange; 03-06-08 at 04:13 PM. Reason: removed URL markup
Reply With Quote
  #9  
Old 03-06-08, 08:42 PM
freerange freerange is offline
New Member
 
Join Date: Mar 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
I ended up going down a slightly different path, but figured out where most of the issue is. I had to use %{QUERY_STRING} to get the entire line including the parameters that were being passed after the ?.

I converted to using a couple of RewriteCond's and a RewriteRule instead:
RewriteCond %{REQUEST_URI} ^/mm5/merchant.mvc$ [NC]
RewriteCond %{QUERY_STRING} ^Screen=PROD&Product_Code=ABC123$
RewriteRule ^.*$ http://foobar.com/ABC123?

I don't have the Product_Code generalized yet, so I have coded the couple of entries I am concerned about for now and will pass as variables when I figure it out (hopefully tomorrow).

-Derrick

Quote:
Originally Posted by freerange View Post
Hi,
This is a great forum, thanks for your time.
I have the same need as this poster, but the various solutions don't seem to be working. Other redirects are working without any problems, just these with the ? being passed into them.

Source string from search engine link:
http://www.foobar.com/mm5/merchant.mvc?Screen=PROD&Product_Code=ABC123

Desired redirected string:
http://www.foobar.com/ABC123

Here is what I have tried...
DirectoryIndex home.php index.php
Options +FollowSymLinks
RewriteEngine On
RedirectMatch 301 (.*mm5)(.*Product_Code=)(.*)$ http://www.foobar.com/$3

It matches until I request anything to match after the ? in the original string. Then it just hits my page not found redirect to the homepage.

Any thoughts as to what I am doing wrong?

Thanks! - Derrick
Reply With Quote
  #10  
Old 03-07-08, 12:36 AM
curbview.com's Avatar
curbview.com curbview.com is offline
Junior Code Guru
 
Join Date: May 2006
Posts: 555
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by freerange View Post
Hi,

I have the same need as this poster, but the various solutions don't seem to be working.
To be honest, the code for him will not work in your situation because you are not trying to achieve what Snaip was trying to achieve. I hope you have studied as to why the same code does not work but it would with modification.
__________________
Whatever you decide, you should make sure best security methods are used and practiced. Should you really need more help, PM me.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Really complex redirect 301 - need help! Josie ASP 2 07-08-06 05:22 PM
Permanent 301 Redirect to new Domain's URL giving me problems in .htaccess cebuy HTML/XHTML/XML 1 03-10-06 11:34 PM
.htaccess problem with new host SugarChick Web Servers 0 02-07-06 04:56 PM
.htaccess and PHP Redirect problem dodod PHP 3 06-19-05 11:56 PM
html/php form for .htaccess validation Boat_2005 PHP 1 03-29-05 04:29 PM


All times are GMT -5. The time now is 03:49 AM.
vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.2 (Unregistered)