2015-09-04 70 views
-1

我搜索并尝试了几种可能的解决方案。缩短动态网址的问题

我开始:

 
http:// example.com/ 729/start-page.asp?cid=4004 
http:// example.com/ 729/start-page.asp?cid=7916 

,并试图为:

 
http:// example.com/ johns-start-page 
http:// example.com/ judys-start-page 

或者如果可能的话:

 
http:// johns-start-page.example.com/ 
http:// judys-start-page.example.com/ 

到目前为止我有:

 
RewriteEngine on 
RewriteCond %{QUERY_STRING} ^cID=4004$ 
RewriteRule ^729\.asp$ /johns-start-page [NC,R=301,L] 

RewriteCond %{QUERY_STRING} ^cID=7916$ 
RewriteRule ^729\.asp$ /judys-start-page [NC,R=301,L] 
+0

@Jon Lin,试过你的第一个解决方案,但它被忽略了。不确定{THE_REQUEST}是否是占位符或 RewriteCond%{THE_REQUEST}是否逐字进入代码。 – fitcher

+0

这是我在SO上的第一个问题。我现在看到,这是一个严重问题或-2投票平原蹩脚问题。我本可以在更好的问题上使用建议,而不是踢屁股。非常感谢。 – fitcher

回答

2

只要你硬编码这些事情,你可以尝试:

RewriteEngine On 

RewriteCond %{THE_REQUEST} \ /+729/start-page.asp\?cid=4004($|\ |\&) 
RewriteRule^/johns-start-page? [L,R=301] 

RewriteCond %{THE_REQUEST} \ /+729/start-page.asp\?cid=7916($|\ |\&) 
RewriteRule^/judys-start-page? [L,R=301] 

RewriteRule ^johns-start-page$ /729/start-page.asp?cid=4004 [L,QSA] 
RewriteRule ^judys-start-page$ /729/start-page.asp?cid=7916 [L,QSA] 

对于子域,你将需要确保你的DNS设置指向这些子域相同的IP地址。然后像这样:

RewriteEngine On 

RewriteCond %{HTTP_HOST} !^johns-start-page\.example\.com$ [NC] 
RewriteCond %{THE_REQUEST} \ /+729/start-page.asp\?cid=4004($|\ |\&) 
RewriteRule^http://johns-start-page.example.com/? [L,R=301] 

RewriteCond %{HTTP_HOST} !^judys-start-page\.example\.com$ [NC] 
RewriteCond %{THE_REQUEST} \ /+729/start-page.asp\?cid=7916($|\ |\&) 
RewriteRule^http://judys-start-page.example.com/? [L,R=301] 

RewriteCond %{HTTP_HOST} ^johns-start-page\.example\.com$ [NC] 
RewriteRule ^$ /729/start-page.asp?cid=4004 [L,QSA] 

RewriteCond %{HTTP_HOST} ^judys-start-page\.example\.com$ [NC] 
RewriteRule ^$ /729/start-page.asp?cid=7916 [L,QSA] 

但是,除非你设置它们包括FQDN,否则所有的链接都可能中断。