Is It Possible to Alter the Displayed URL from the Actual URL?
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开发者_如何学Python 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!
Use permalinks
To configure the URL address in a wordpress site. Visit the dashboard and under Settings
you will find the Permalinks
link.
@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?
"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.
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.)
精彩评论