Jump to content

Always Show REQUEST_URI Instead Of Actual Link?


steven fullman

Recommended Posts

Hello,

 

I sincerely help you can help with this scenario... :confused:

 

I'm not sure this is possible, but here goes:

 

I have a Wordpress blog, installed in a subdirectory of my website, e.g. http://www.mydomain.com/demo/

 

I have some permalinks, which all follow the same structure, like this:

 

http://www.mydomain.com/demo/goto/google

 

http://www.mydomain.com/demo/goto/yahoo

 

http://www.mydomain.com/demo/goto/bing

 

etc...i.e they all have /goto/*somewhere* (and the *somewhere* is a redirect to an external site).

 

Wordpress handles the permalinks itself, as you can see in the .htaccess file Wordpress automatically generates:

 

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /demo/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /demo/index.php [L]
</IfModule>
# END WordPress

 

 

Here's what I'd REALLY like to happen (if possible)...

 

  • I link to one of my custom permalinks in a blog post on mydomain.com, e.g. mydomain.com/goto/phpfreaks
  • When a visitor clicks that link, the URL in the address bar should display as the page they are currently on

 

So, here's what it looks like:

 

My blog has a post called: http://mydomain.com/demo/my-test-post

 

On that page, there's a link to: http://mydomain.com/goto/phpfreaks (which redirects to phpfreaks.com)

 

When the visitor clicks that link, I don't want them to see the redirect URL in the address bar, so they see:

 

http://mydomain.com/demo/my-test-post => click link => http://phpfreaks.com

 

...instead of:

 

http://mydomain.com/demo/my-test-post => click link =>  http://mydomain.com/goto/phpfreaks => http://phpfreaks.com

 

This sounds like something that should be possible using mod_rewrite...doesn't it?

 

i.e. display REQUEST_URI for any link like /goto/*

 

Does that make sense...and is it possible?

 

Your help would be greatly appreciated, as I have been really struggling trying to get to grips with mod_rewrite & .htaccess!

 

Many thanks,

Steve

 

Link to comment
Share on other sites

Hi cags,

 

Thank you so much for your reply...and I'm not surprised you don't understand me  :D

 

...I'm notoriously BAD at explaining things!

 

AND I'm a mod_rewrite newbie...

 

Having said that, let me try to explain a little better!

 

OK,

 

My visitor clicks on an internal link, e.g. : http://www.mydomain.com/goto/phpfreaks

 

...which will redirect them to phpfreaks.com

 

(we need to assume the link address is obfuscated, so they can't see it in their browser status bar if they hovered over it)

 

I NEED them to visit http://www.mydomain.com/goto/phpfreaks in order to drop a cookie.

 

So, they click on http://www.mydomain.com/goto/phpfreaks ...I drop a cookie, and then I immediately redirect them to phpfreaks.com

 

BUT, my question is: I don't want my visitor to **see** the "intermediate"  http://www.mydomain.com/goto/phpfreaks address...I want them to click the link...and as far as they're concerned, they've gone straight to phpfreaks.com

 

...using mod_rewrite?

 

I'm super-grateful for your help, cags, and I suspect I STILL haven't made myself clear...

 

Just in case, here's another representation:

 

When the visitor clicks that link, I don't want them to see the redirect URL in the address bar...

 

Here's what I want them to see:

 

http://mydomain.com/demo/my-test-post => internal link (/goto/phpfreaks) => they click link => http://phpfreaks.com

 

...what I don't want them to see (in red):

 

http://mydomain.com/demo/my-test-post => internal link (/goto/phpfreaks) => click link =>  http://mydomain.com/goto/phpfreaks => http://phpfreaks.com

 

Blimey! Does that make sense?

 

Kind regards,

Steve

 

 

 

 

 

I'm not sure I'm understanding you. Applying the R flag should redirect so when clicking a link to http://mydomain.com/goto/phpfreaks you would automatically be sent to http://phpfreaks.com (including the browser URL changing).

Link to comment
Share on other sites

I think the simple answer is you can't. When you click the link you have to give the users browser a URL there are no two ways around it.

 

Thanks, Cags. I was hoping I could use mod_rewrite to display the REFERER URI (i.e. the same URL which had the link in the first place) instead of the /goto/somewhere URL.

 

In pseudo-code:

 

For any URL matching the pattern /goto/*, display the REFERER URI in the address bar instead.

 

Is that not possible? 

 

Thanks again cags. I really appreciate your time.

 

Best wishes,

Steve

Link to comment
Share on other sites

Whatever URL you use has to be unique to that purpose. So no you can't do that. The mod_rewrite module is simply a way of taking requests to the server and passing information back to the client that requested it, it has no ability to change the URL in the address bar other than by telling the client a file is in a different location and sending that location back to the client. The client then requests that file instead, the URL must have identifying information in it for the link that you wish to actually go to. The only way around this I can think of would be to use frames to mask the URL in the address bar.

Link to comment
Share on other sites

Whatever URL you use has to be unique to that purpose. So no you can't do that. The mod_rewrite module is simply a way of taking requests to the server and passing information back to the client that requested it, it has no ability to change the URL in the address bar other than by telling the client a file is in a different location and sending that location back to the client. The client then requests that file instead, the URL must have identifying information in it for the link that you wish to actually go to. The only way around this I can think of would be to use frames to mask the URL in the address bar.

 

Hi cags,

 

I understand...but if I can ask one more question...

 

...(well, maybe two)...

 

OK, so the URL *has* to be unique, but is it possible for mod_rewrite to "capture" the referrer url, and change it slightly...

 

e.g. the referring url is http://mydomain.com/some-post/

 

and using mod_rewrite, change it to http://mydomain.com/some-post/1

 

...where the 1 "masks" the /goto/somewhere/ instead ?

 

 

Many thanks,

Steve

Link to comment
Share on other sites

That is essentially what services like bit.ly are for. You enter a URL, it generates a random string, whenever you go to bit.ly/random it goes to your URL. It does this by storing the two values (the random number, the actual URL) together somewhere so it can lookup one when it receives the other. mod_rewrite matches patterns only, it doesn't make any database look-ups to compare the values, which means you would be linking to another file that does the work. This file would then have to redirect to the page when it has found the right value. Maybe that's what you want, I don't know, because frankly I don't uderstand the point. It sounds like you wish to redirect people to an address without them knowing where they are going. I can see no real reason for this other than to shorten a URL in which case you should just use a URL shortening service.

Link to comment
Share on other sites

That is essentially what services like bit.ly are for. You enter a URL, it generates a random string, whenever you go to bit.ly/random it goes to your URL. It does this by storing the two values (the random number, the actual URL) together somewhere so it can lookup one when it receives the other. mod_rewrite matches patterns only, it doesn't make any database look-ups to compare the values, which means you would be linking to another file that does the work. This file would then have to redirect to the page when it has found the right value. Maybe that's what you want, I don't know, because frankly I don't uderstand the point. It sounds like you wish to redirect people to an address without them knowing where they are going. I can see no real reason for this other than to shorten a URL in which case you should just use a URL shortening service.

 

Thanks, cags :)

 

I've sent you a PM, I hope that's OK.

 

Kind regards,

Steve

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.