I just changed url schemes, so example.com/ugly is now example.com/nice
example.com/ugly still handles the request - .htaccess has this r开发者_开发知识库ule:
RewriteRule ^nice$ example.com/ugly [PT,L,QSA]
This much works.
Now I'd like to redirect example.com/ugly to example.com/nice, but still have example.com/ugly handle the request. Something like this:
- Redirect example.com/ugly to example.com/nice (301)
- Internally redirect example.com/nice to example.com/ugly, without letting the user know, and without repeating step 1
Simple ways of doing this lead to looping of course. Is there a way to do this with .htaccess? If not, is there another way?
The best way I know of is using PHP in the target file. Here's approximately what you'd want to add:
if($_SERVER['REQUEST_URI'] == '/index.php') header("Location: http://".$_SERVER['HTTP_HOST']."/");
Obviously you need to add some other variables in there to handle whatever requests, but that's the basic idea.
精彩评论