0

We had a major site rework and now our new site is PHP based. We have some sites which have our old pages linked to them which were asp pages in the past. I want to create a htaccess rule but I have failed to get the desired result. If anyone can help it would be great.

The incoming pages will be in the format

http://www.mysite.com/tour.asp?id=1234

where 1234 is dynamic and can vary. I want to redirect this to the page viewer.php and change the query string variable id to tourid so the page requested should be

http://www.mysite.com/viewer/1234

I have another rule in htaccess which routs the above url to

http://www.mysite.com/viewer.php?tourid=1234 (this is working)

I need a rule by which the 1st url is routed to the 2nd one hoping it will open the 3rd url. How can i achieve this?

Since I am new to htaccess, can someone help me around how to achieve this routing? I want to clear here that the server now is php and I have to accomplish this using htaccess only. I followed other similar questions but found none that answers my query.

4

1 回答 1

1

UPADTE - 我第一次弄错了,这是更正的版本。

# Match and capture the id value from the URL
RewriteCond %{QUERY_STRING} id=([0-9]+)
# Redirect by passing the ID to the new site - the ? at the end removes existing query string
RewriteRule tour.asp http://www.mysite.com/viewer/%1? [R=301,L]

我假设 ID 只是数字。

此答案的来源位于https://httpd.apache.org/docs/2.2/mod/mod_rewrite.html - 搜索“修改查询字符串”以查找有关删除查询字符串的信息。

于 2013-07-12T10:00:17.047 回答