steven fullman Posted February 27, 2010 Share Posted February 27, 2010 Hello, I sincerely help you can help with this scenario... 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 Quote Link to comment Share on other sites More sharing options...
cags Posted February 27, 2010 Share Posted February 27, 2010 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). Quote Link to comment Share on other sites More sharing options...
steven fullman Posted February 27, 2010 Author Share Posted February 27, 2010 Hi cags, Thank you so much for your reply...and I'm not surprised you don't understand me ...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). Quote Link to comment Share on other sites More sharing options...
cags Posted February 28, 2010 Share Posted February 28, 2010 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. Quote Link to comment Share on other sites More sharing options...
steven fullman Posted February 28, 2010 Author Share Posted February 28, 2010 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 Quote Link to comment Share on other sites More sharing options...
cags Posted February 28, 2010 Share Posted February 28, 2010 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. Quote Link to comment Share on other sites More sharing options...
steven fullman Posted February 28, 2010 Author Share Posted February 28, 2010 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 Quote Link to comment Share on other sites More sharing options...
cags Posted February 28, 2010 Share Posted February 28, 2010 Providing the 1 is unique to that address and you have some way of tying up the 1 to the address then yes. But I doubt it would do what you want. Quote Link to comment Share on other sites More sharing options...
steven fullman Posted February 28, 2010 Author Share Posted February 28, 2010 Providing the 1 is unique to that address and you have some way of tying up the 1 to the address then yes. But I doubt it would do what you want. Hi cags, The 1 would be unique, and I'm intrigued why you don't think it would achieve the result! Kind regards, Steve Quote Link to comment Share on other sites More sharing options...
cags Posted February 28, 2010 Share Posted February 28, 2010 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. Quote Link to comment Share on other sites More sharing options...
steven fullman Posted February 28, 2010 Author Share Posted February 28, 2010 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.