简体   繁体   中英

Issue shortening dynamic URLs

I've searched and tried several possible solutions.

I begin with:

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

and trying for:

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

or if possible:

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

so far I've got:

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]

As long as you're hardcoding these things, you can try:

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]

For the subdomains, you're going to need to make sure you have DNS setup to point those subdomains to the same IP address. Then something like:

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]

But all your links could break unless you've set them up to include a FQDN.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM