1

On my website, I would rename the URL on address bar, from

domain.com/economy/article.php?id=00

to

domain.com/economy/id-name-article.html

I wrote this .htaccess file:

RewriteEngine On
RewriteRule ^([0-9]+)-([^\.]*)\.html$ http://domain.com/economy/article.php?id=$1 [L]

I have an anchor with this href: href="economy/id-name-article.html" and when I click on it, the server is redirected on article.php, it runs the script in the correct way and I can view the article, but on the address bar is still written domain.com/economy/article.php?id=00 instead domain.com/economy/id-name-article.html. Why?

This happens only on my online server, while locally it's all right.

4

1 回答 1

1

The mod_rewrite module is issuing a redirect to your browser rather than transparently rewriting the url, causing you to see the new url in your browser.

Try removing the http://domain.com portion from your RewriteRule to see if it avoids the redirect to your browser by changing the rule to:

RewriteRule ^([0-9]+)-([^\.]*)\.html$ /economy/article.php?id=$1 [L]

If that fails, you could also use the proxy flag [P] to force apache to transparently fetch the page and return it to your users without the redirect. I don't recommend this approach since it can have security implications but it should work if the above doesn't.

EDIT: To clarify, rewriting the url with a fully-qualified domain rather than a relative uri tells apache that the redirect is on a different server, and therefore it doesn't know that the new url is accessible on the same host without redirecting the client.

于 2013-07-04T23:55:31.243 回答