Forum Moderators: phranque
I'm trying to redirect a URL that looks like this:
[mydomain.com...]
to
[mydomain.com...]
When 200 is the variable id of document (they are 200+ documents)
What's wrong with this code?:
RedirectMatch 301 news/view_news.php?what=(.*) [mydomain.com...]
also I tried with
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^/news/view_news.php?what=(.*)$ [mydomain.com...] [L,R=301]
It does not work of any way.
Please help me!
Excuses by my horrible English. Thank you very much.
RedirectMatch 301 news/view_news.php?what=(.*) [mydomain.com...]
The dot isn't escaped in the first line, and neither is the question mark. Plus you might try ^ and $ to indicate beginning and end of string. So:
RedirectMatch 301 ^news/view_news\.php\?what=(.*)$ [mydomain.com...]
Are you trying to rewrite the URL? If so:
RewriteRule ^news([0-9]{3})\.html$ /news/view_news.php?what=$1
The above assumes that the number part of the URL is always 3 digits long.
Also, I've found that if you want to redirect URLs from the one you're rewriting to, it won't work. For example, if you're redirecting from direct requests for news_views.php, and then rewriting the URLs so they point to view_news.php, you're setting up the server to follow an infinite loop.
A good point about this problem. The solution is to use %{THE_REQUEST} as a condition for the redirect, so that the redirect is only invoked for direct client requests of the dynamic URL, and not as the result of an internal rewrite.. The solution is posted here in several threads.
To clarify. In many cases, if you have a site that previously published dynamic URLs, you will want to publish new static URLs on your pages and internally rewrite your new static URLs to dynamic URLs when requested. But you will probably also want to exteranlly redirect client requests for the old dynamic URLs to the new static URLs, so that search engines will drop the old dynamic links and show your new static links.
This can lead to an 'infinite loop' as the two functions repeatedly undo each other's action. And the cure is to use %{THE_REQUEST} as a condition on the redirect.
Jim