[SOLVED] .htaccess 301 redirect

02-29-08, 10:18 AM
|
 |
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
|

02-29-08, 10:19 AM
|
 |
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.
|

02-29-08, 10:26 AM
|
 |
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
|

03-01-08, 09:00 AM
|
 |
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.
|

03-01-08, 09:16 AM
|
 |
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.
|

03-01-08, 09:50 AM
|
 |
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.
|

03-01-08, 10:08 AM
|
 |
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. 
|

03-06-08, 04:06 PM
|
|
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
|

03-06-08, 08:42 PM
|
|
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
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
|
|

03-07-08, 12:36 AM
|
 |
Junior Code Guru
|
|
Join Date: May 2006
Posts: 555
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by freerange
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.
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Hybrid Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|