Issue shortening dynamic URLs

58 views Asked by At

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]
1

There are 1 answers

0
Jon Lin On

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.