views:

63

answers:

4

I posted a question the other day about how to change the displayed URL on a Wordpress-generated page, specifically from something like "mysite.com/?cat=3" to just "mysite.com". I got a few replies that steered me towards doing some type of redirect with .htacess. After some research and experimentation, I realized that it's not so much a redirect I need but just some way to alter the displayed URL in the browser.

Part of the challenge is that the page in question is dynamically generated by a combination of standard WP code, a WP event calendar plugin (the-events-calendar), and some custom code a developer added. I've played around with permalinks and the category slug, but I can't get the desired result.

The bigger question, I think, is: "Is it possible for a web server to deliver, for example, 'xyz.com/somedir/somefile.php?withsomequerystring=yes' but instruct the browser to show the URL as 'xyz.com/pretty-url' ?"

Hackers seem to be able to do all sorts of evil things to make people think they're on one web page/site when they're actually somewhere else. I would think what I'm asking is possible through htaccess/mod_rewrite, but I don't know how to achieve it. I've been banging my head against the wall on this for several weeks, so I would be thrilled if anyone had a good suggestion.

Thanks!

A: 

"Is it possible for a web server to deliver, for example, 'xyz.com/somedir/somefile.php?withsomequerystring=yes' but instruct the browser to show the URL as 'xyz.com/pretty-url' ?"

You can't make the browser show a different URL than the one it's on. But what you can do, as you already say, is use mod_rewrite to internally translate xyz.com/pretty-url into the URL you mention.

Pekka
Right, but I need to do it backwards from what you suggest - I need to translate the "ugly" URL to the "pretty" one. Doesn't do me much good to go the other way.
@webwiz I see. That is theoretically possible, also using `.htaccess`, but would involve a header redirect which would screw up form submissions and such. Feels complicated to me.
Pekka
The address in the address bar is the address hat was requested by the browser. If you wish to use "Pretty URL's", you should be updating the links on your site to link to the Pretty URL's, then using mod_rewrite to convert them on the fly so your application still works.
Cags
A: 

I may tinker with this later - I'm at work. But I think this isn't too hard.

What I'm hearing that you want to do is this: The user (the browser, rather) requests the ugly URL, you want to show what's at the ugly URL, but you want them to see the pretty URL.

The short answer is do a header redirect from the ugly url to the pretty url, and then do an internal rewrite of the pretty URL as the ugly URL.

You'll have to look up how to do those two things yourself, but they aren't hard. Also, you will want to either make the header redirect higher priority than the rewrite (place it higher up in .htaccess) or make the internal rewrite the last rewrite (put [l] flag after the RewriteRule), so that the redirects don't loop.

You mentioned lots of custom code, though, and with this solution, that code will see that request came from the pretty URL. (And relative script/image/stylesheet references will resolve relative to the pretty URL, but relative URLs in Wordpress would be very silly.)

Jesse Millikan
A: 

@webwiz: You might find this answer I posted just 10 minutes ago to be helpful.

I might be able to help some more but I need to understand what it is on your server that actually generates the URLs for the following format:

http://xyz.com/somedir/somefile.php?withsomequerystring=yes

that you want converted to:

http://xyz.com/pretty-url

I'm wondering if any of them are routed through any of the *_link hooks I described in the other post?

MikeSchinkel
Wow, Mike, that is *some* answer! I may try some of the ideas it sparked, but I have to digest the knowledge first. As I said to another respondent, the main WP page (.../themes/name/index.php) does a PHP 301 redir to mysite.com/?cat=3. That (virtual) page is built by the calendar plugin, pulling content from another php file into an iframe. Seems to be the usage (hijacking?) of a category page (with a URL I can't "pretty up") that's the crux of the problem.
If you need to iframe within a category page you can do that. Check out this to see which file controls your category display: http://codex.wordpress.org/Category_Templates#What_Template_File_is_Used.3F
MikeSchinkel
A: 

@Jesse Millikan - Here's what I think is happening...

1) mysite.com/index.php loads the first Wordpress page at...

2) mysite.com/wp-content/themes/themename/index.php which has a 301 redirect at the top:

http://mysite.com/?cat=3"); exit(); ?>

3) mysite.com/?cat=3 is the events calendar monthly view page and it loads (as an iframe, I think)...

4) mysite.com/wp-content/plugins/the-event-calendar/views/monthlyview.php

The browser shows "mysite.com/?cat=3" which seems kind of ugly to me. I think the calendar plugin is making use of WP's categories to put its stuff on a a page (but without showing any posts in that category, of which there are none). For whatever reason, it seems to be using a category page a the "vehicle" to do its work.