homepage Welcome to WebmasterWorld Guest from 54.196.189.229
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
.php?url=ZZZZ same as .php?url=http%3A%2F%2F%2F.*snip*.ZZZZ
Then example.info/url/ZZZZZZZZZ/
Jesse_Smith




msg:4110480
 3:26 am on Apr 6, 2010 (gmt 0)

How do you make

http://www.example.info/index.php?url=ZZZZZZZZZ

be the same thing as the working URL

http://www.example.info/index.php?url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DZZZZZZZZZ

And then have

http://www.example.info/url/ZZZZZZZZZ/

be the mod_rewrited URL they can both be redirected to?


Options +Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^url/(.*)\s(.*)/$ http://www.example.info/url/$1$2/ [R=301,L]
RewriteRule ^url/([^.]+)/$ index.php?url=$1 [L]
RewriteRule ^link/([^.]+)/$ free_youtube_video_exposure.php?url=$1 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php\?url=http\%3A\%2F\%2Fwww\.youtube\.com\%2Fwatch\%3Fv\%3D([^\ ]+)\ HTTP/
RewriteRule ^index\.php$ http://www.example.info/url/%1/? [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php\?url=([^\ ]+)\ HTTP/
RewriteRule ^index\.php$ http://www.example.info/url/%1/? [R=301,L]

 

jdMorgan




msg:4110786
 2:45 pm on Apr 6, 2010 (gmt 0)

It looks like you've got half of that already coded -- not sure, since your code contains no comments, though.

Do you want to 301- or 302- redirect to the video site, or do you wish to reverse-proxy the request (if allowed by your hosting configuration)?

Jim

Jesse_Smith




msg:4110878
 5:18 pm on Apr 6, 2010 (gmt 0)

301 from

http://www.example.info/index.php?url=ZZZZZZZZZ

and

http://www.example.info/index.php?url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DZZZZZZZZZ

redirecting to

http://www.example.info/url/ZZZZZZZZZ/

with the original URL being the long static URL. The URLs would be generated from a form, not actual links, so I wouldn't have to worry about search engine stuff.

Right now the only type of URL that works is

index.php?url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DZZZZZZZZZ

Options +Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
#Make short URL work, if it can be done.
RewriteRule ^url/([^.]+)/$ index.php?url=$1 [L]

#Make long URL work. Something like this...
RewriteRule ^url/([^.]+)/$ index.php?url=http\%3A\%2F\%2Fwww\.youtube\.com\%2Fwatch\%3Fv\%3D$1 [L]

But the 'RewriteRule cannot 'see' query strings.' I think makes a restricton to this.

#Long URL redirect.
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php\?url=http\%3A\%2F\%2Fwww\.youtube\.com\%2Fwatch\%3Fv\%3D([^\ ]+)\ HTTP/
RewriteRule ^index\.php$ http://www.example.info/url/%1/? [R=301,L]
#Short URL redirect.
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php\?url=([^\ ]+)\ HTTP/
RewriteRule ^index\.php$ http://www.example.info/url/%1/? [R=301,L]

jdMorgan




msg:4110977
 7:37 pm on Apr 6, 2010 (gmt 0)

RewriteRule cannot see query strings, that is true. So that is why the rule must use a RewriteCond to examine the query string, which it does.

Further, examining THE_REQUEST ensures that you are looking at the actual string sent by the browser, without any URL-decoding of the escaped characters such as "%2f" (which is an encoded "/".

So the first part of that rule is fine, and the only thing I'd add is that you may need to add the [NE] flag to that rule's flags, as well as to any other rule that needs to pass "%" characters unchanged. See mod_rewrite RewriteRule documentation at apache.org for details on the [NE] flag.

Note that the two Options directives may be combined on one line, simply listing all of the arguments separated by spaces.

Jim

Jesse_Smith




msg:4111072
 10:34 pm on Apr 6, 2010 (gmt 0)

Both 301 redirects are working, but it's acting like

example.info/url/whatever/

comes from

example.info/index.php?url=ZZZZZZZZ

instead of

example.info/index.php?url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DZZZZZZZZ

I think I got NE in the right spots.

Options +Indexes FollowSymlinks
RewriteEngine on
RewriteBase /
#******I think this one needs messed with******
#Make long URL be same as example.com/url/whatever/.
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php\?url=http\%3A\%2F\%2Fwww\.youtube\.com\%2Fwatch\%3Fv\%3D([^\ ]+)\ HTTP/
RewriteRule ^index\.php$ http://www.example.info/url/%1/? [L,NE]

#Make short URL be same as example.com/url/whatever/.
RewriteRule ^url/([^.]+)/$ index.php?url=$1 [L]
RewriteRule ^url/(.*)\s(.*)/$ http://www.example.info/url/$1$2/ [R=301,L]

#Long URL redirect.
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php\?url=http\%3A\%2F\%2Fwww\.youtube\.com\%2Fwatch\%3Fv\%3D([^\ ]+)\ HTTP/
RewriteRule ^index\.php$ http://www.example.info/url/%1/? [R=301,L,NE]

#Short URL redirect.
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php\?url=([^\ ]+)\ HTTP/
RewriteRule ^index\.php$ http://www.example.info/url/%1/? [R=301,L,NE]

Jesse_Smith




msg:4111130
 12:36 am on Apr 7, 2010 (gmt 0)

Thanks. I got it now.

RewriteRule ^url/([^.]+)/$ index.php?url=http\%3A\%2F\%2Fwww\.youtube\.com\%2Fwatch\%3Fv\%3D$1 [L]

I was thinking another RewriteCond was needed for that one.

Options +Indexes FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^url/([^.]+)/$ download.php?url=http\%3A\%2F\%2Fwww\.youtube\.com\%2Fwatch\%3Fv\%3D$1 [L]

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /download\.php\?url=http\%3A\%2F\%2Fwww\.youtube\.com\%2Fwatch\%3Fv\%3D([^\ ]+)\ HTTP/
RewriteRule ^download\.php$ http://www.example.info/url/%1/? [R=301,L,NE]

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /download\.php\?url=([^\ ]+)\ HTTP/
RewriteRule ^download\.php$ http://www.example.info/url/%1/? [R=301,L,NE]

g1smd




msg:4111213
 5:48 am on Apr 7, 2010 (gmt 0)

There's no need to escape stuff in the target of the redirect. You only need to escape special characters reserved by Mod_Rewrite when they are used in the patterns.

DO add a
# comment before each rule block explaining exactly what it does. This is for 6 or 12 months later when you look back at the file and suddenty it's not so clear what it all does.
Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved