Help with .htaccess url rewrite

  • Shadows
  • Beginner
  • Beginner
  • No Avatar
  • Joined: Oct 03, 2006
  • Posts: 64
  • Status: Offline

Post December 23rd, 2006, 2:38 pm

Hello,

I'm having a problem with one of my htaccess rewrites with the following rule:

Code: [ Download ] [ Select ]
ReWriteRule ^link/(.*)$ goto.php?l=$1 [L]


regular links are fine but any link with a ? in makes the rewrite strip the rest of the link off:

Code: [ Download ] [ Select ]
e.g.

/link/http://www.myfoxchicago.com/myfox/pages/Home/Detail?contentId=1823428&version=1&locale=EN-US&layoutCode=VSTY&pageId=1.1.1

Outputs:

http://www.myfoxchicago.com/myfox/pages/Home/Detail
  1. e.g.
  2. /link/http://www.myfoxchicago.com/myfox/pages/Home/Detail?contentId=1823428&version=1&locale=EN-US&layoutCode=VSTY&pageId=1.1.1
  3. Outputs:
  4. http://www.myfoxchicago.com/myfox/pages/Home/Detail


Any suggestions? I dont want the symbol ? in links stripped out with the remaining url.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post December 23rd, 2006, 2:38 pm

  • b_heyer
  • Web Master
  • Web Master
  • User avatar
  • Joined: Jun 15, 2003
  • Posts: 4584
  • Loc: New York
  • Status: Offline

Post December 24th, 2006, 12:08 am

Try this out and let me know...

Code: [ Download ] [ Select ]
ReWriteRule ^link/(.*)$ goto.php?l=$1 [L,QSA]
Pixel Acres V2
  • Prime
  • Professor
  • Professor
  • User avatar
  • Joined: Dec 05, 2005
  • Posts: 935
  • Loc: Liverpool
  • Status: Offline

Post December 24th, 2006, 2:30 am

Hi,

The rest of your URL is made up of parameters therefore, it's probably best capturing them as $1, $2, $3 etc ... and redefining them within your rewrite.

Hope that makes sense.

Cheers, Prime ... :D
my seo experience
  • b_heyer
  • Web Master
  • Web Master
  • User avatar
  • Joined: Jun 15, 2003
  • Posts: 4584
  • Loc: New York
  • Status: Offline

Post December 24th, 2006, 11:21 am

apache.org wrote:
# 'qsappend|QSA' (query string append)
This flag forces the rewrite engine to append a query string part of the substitution string to the existing string, instead of replacing it. Use this when you want to add more data to the query string via a rewrite rule.


By putting that flag in there it will do the capturing for them. Since modrewrite ignores the query strings (anything after the ?) you have to tell it to append them back in. My code *might* also need an & after the $1:
Code: [ Download ] [ Select ]
ReWriteRule ^link/(.*)$ goto.php?l=$1& [L,QSA]


That way when it appends the & is already in place, I can't remember if the server does it automatically or not. You may want to test with replacing L with R to see exactly what is getting sent to the server.
Pixel Acres V2
  • Shadows
  • Beginner
  • Beginner
  • No Avatar
  • Joined: Oct 03, 2006
  • Posts: 64
  • Status: Offline

Post December 24th, 2006, 2:04 pm

well currently I'm using

Code: [ Download ] [ Select ]
RewriteEngine On
ReWriteRule ^link/(.*)$ goto.php?l=$1& [L,QSA]
  1. RewriteEngine On
  2. ReWriteRule ^link/(.*)$ goto.php?l=$1& [L,QSA]


and it still wont work, no idea why so I'm just using goto.php?l=LINK with my bbcode function.
  • b_heyer
  • Web Master
  • Web Master
  • User avatar
  • Joined: Jun 15, 2003
  • Posts: 4584
  • Loc: New York
  • Status: Offline

Post December 24th, 2006, 2:16 pm

Code: [ Download ] [ Select ]
RewriteEngine On
ReWriteRule ^link/(.*)$ goto.php?l=$1& [R,QSA]
  1. RewriteEngine On
  2. ReWriteRule ^link/(.*)$ goto.php?l=$1& [R,QSA]


If you use that, what is the url in the address bar? (after you click the link or what not)
Pixel Acres V2
  • Shadows
  • Beginner
  • Beginner
  • No Avatar
  • Joined: Oct 03, 2006
  • Posts: 64
  • Status: Offline

Post December 24th, 2006, 2:27 pm

link is

Code: [ Download ] [ Select ]
/link/http://www.apniisp.com/forum/index.php?showtopic=32616


OUTPUT:

Code: [ Download ] [ Select ]
http://www.wjdev.net/home/Shadows/public_html/wjdev/goto.php?l=http://www.apniisp.com/forum/index.php&&showtopic=32616


which quickly redirects back to my homepage
  • b_heyer
  • Web Master
  • Web Master
  • User avatar
  • Joined: Jun 15, 2003
  • Posts: 4584
  • Loc: New York
  • Status: Offline

Post December 24th, 2006, 2:49 pm

Code: [ Download ] [ Select ]
RewriteEngine On
ReWriteRule ^link/(.*)$ goto.php?l=$1 [L,QSA]
  1. RewriteEngine On
  2. ReWriteRule ^link/(.*)$ goto.php?l=$1 [L,QSA]


What about that?

And does just http://www.wjdev.net/home/Shadows/publi ... ?l=http:// http://www.apniisp.com/forum/index.php&showtopic=32616
work for you? (I get a 404 error for that, and even just http://www.wjdev.net/home/Shadows/public_html/wjdev/)
  • Shadows
  • Beginner
  • Beginner
  • No Avatar
  • Joined: Oct 03, 2006
  • Posts: 64
  • Status: Offline

Post December 24th, 2006, 2:53 pm

well that gets through to the goto.php script but splits again with the ? symbol. wjdev is my testing domain:

live:

http://www.socketz.com/link/http://www. ... opic=32616
  • Shadows
  • Beginner
  • Beginner
  • No Avatar
  • Joined: Oct 03, 2006
  • Posts: 64
  • Status: Offline

Post December 24th, 2006, 2:54 pm

do you see the output I'm getting, thanks for your patience b_heyer

goto.php script

PHP Code: [ Download ] [ Select ]
 
   $url = strip_tags($_REQUEST['l']);
 
   echo($url);
 
   exit();
 
 
  1.  
  2.    $url = strip_tags($_REQUEST['l']);
  3.  
  4.    echo($url);
  5.  
  6.    exit();
  7.  
  8.  
  • b_heyer
  • Web Master
  • Web Master
  • User avatar
  • Joined: Jun 15, 2003
  • Posts: 4584
  • Loc: New York
  • Status: Offline

Post December 24th, 2006, 3:00 pm

check out your other post, I posted a possible solution there.
Pixel Acres V2

Post Information

  • Total Posts in this topic: 11 posts
  • Users browsing this forum: Bozebo, cleartango and 414 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© Unmelted Enterprises 1998-2009. Driven by phpBB © 2001-2009 phpBB Group.