Forum Moderators: phranque
i have program that writes urls as firstname_lastname.domain.com then redirects the request to domain.com/file.php?p=firstname_lastname
the included htaccess file only redirects the requests properly if the fn and ln come out as subdirectories - but still point to the same final destination. the option of putting the names as subdomains that redirect to a php file in a subdirectory can be done but the htaccess file isn't autmatically updated.
here's the original htaccess
RewriteEngine On
RewriteRule^.*\.php$-[NC,L]
RewriteCond%{REQUEST_FILENAME}!-f
RewriteCond%{REQUEST_FILENAME}!-d
RewriteRule^([^/]*)[\._]([^/]*)(_debugclickheat)?\.html$purl.php?purl=$1_$2&$3[L]
RewriteCond%{REQUEST_FILENAME}!-f
RewriteCond%{REQUEST_FILENAME}!-d
RewriteRule^([^/]*)[\._]([^/]*)/?(debugclickheat)?$purl.php?purl=$1_$2&$3[L]
RewriteCond%{REQUEST_FILENAME}!-f
RewriteCond%{REQUEST_FILENAME}!-d
RewriteRule^.*$purl.php[L]
#Directoryindex purl.php
and what i've screwed around with:
Options +FollowSymlinks
RewriteEngine On
RewriteRule^.*\.php$-[NC,L]
RewriteCond%{REQUEST_FILENAME}!-f
RewriteCond%{REQUEST_FILENAME}!-d
RewriteCond %{REQUEST_URI} !^/
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
#RewriteCond %{HTTP_HOST} ^(^.*)[\._](^.*)\.domain\.com [NC]
RewriteCond %{HTTP_HOST} ^(^.*)[\._](^.*)\.domain\.com
RewriteRule (.*) /purl.php?purl=$1_$2 [L]
#RewriteRule^([^.]+)[\._]([^.]+)\.domain\.com\$www.domain.com/purl.php?purl=$1_$2&$3[L]
#RewriteCond%{REQUEST_FILENAME}!-f
#RewriteCond%{REQUEST_FILENAME}!-d
#RewriteRule^([^/]*)[\._]([^/]*)(_debugclickheat)?\.html$purl.php?purl=$1_$2&$3[L]
#RewriteCond%{REQUEST_FILENAME}!-f
#RewriteCond%{REQUEST_FILENAME}!-d
#RewriteRule^([^/]*)[\._]([^/]*)/?(debugclickheat)?$purl.php?purl=$1_$2&$3[L]
#RewriteCond%{REQUEST_FILENAME}!-f
#RewriteCond%{REQUEST_FILENAME}!-d
#RewriteRule^.*$purl.php[L]
#Directoryindex purl.php
i've tried a lot of variations and haven't had any success. any help would be appreciated. i've also read jdMorgan's post here:http://www.webmasterworld.com/forum92/4332.htm and learned a good bit but without practice i don't know how to apply what i've learned effectively.
i'm running apache 2.2 on windows xp.
thanks.
> i have program that writes urls as firstname_lastname.example.com then redirects the request to example.com/file.php?p=firstname_lastname
Get rid of the part that "redirects the request to example.com/file.php?p=firstname_lastname". You certainly don't want a redirect, which will expose the script and query string to the client, making this whole exercise pointless.
All your 'program' needs to do is to generate the URLs that you want on your pages -- as you want them to appear in the browser address bar and in search engine results listings. It should not do any redirects.
Then when one of those firstname_lastname.example.com links is clicked and is requested from your server, we use mod_rewrite to internally rewrite (not externally redirect) it to your script.
# Internally rewrite requests for <firstname_lastname>.example.com/<anything>
# to /file.php?p=<firstname_lastname> unless it's already been done
RewriteCond %{QUERY_STRING} !&?p=[a-z]+_[a-z]+&?
RewriteCond %{HTTP_HOST} ^([a-z]+_[a-z]+)\.example\.com
RewriteRule ^ file.php?p=%1 [L]
Once you get this new rule working, you'll likely want to add another: A rule to externally redirect direct client requests for <anything>.example.com/firstname_lastname/<any_path> to <firstname_lastname>.example.com/<any_path>
You also need to be aware of a problem hinted-at in the comments I put on this new rule: *All* URL-paths requested from firstname_lastname.example.com are rewritten to the script, and those URL-paths are both ignored and lost. This creates the potential for duplicate content. Consider defining and restricting the URL-path requested from the user-subdomain to "/" or some other single URL-path.
In other words, a request for bill_smith.example.com/anything/whatsoever/can-be#here?is-that-what-you-want will be rewritten to file.php?p=bill_smith, and the rest of the URL-path, fragment, and query string will be ignored. And that's not good, because it means that your site can be abused by competitors' creating bogus links to an infinite number of 'page' URLs, and all will return the content of file.php?p=bill_smith
This will 'infinitely' dilute the page rank of your intended 'real' URLs.
But one thing at a time...
Jim
page rank and such isn't a problem. the program is for personalized urls. the program keeps a list of valid subdomains so if anonymous_bob trys it there's an invalid url page he gets redirected to.
it's used for us when we send out mailers that our customers can respond via their urls so we can keep track of response rate and who responds. it's not spam if that makes difference to you. i work at a printing company and the mailers are mostly for current and old clients and alerting them of new services and such.
btw the all the rules are for different formats for the PURLs. i kept them in the post just incase anyone may have seen any conflicts in rules or maybe a rule that i should keep in. i have emailed the writer of the program but he's very slow about returning mails. i have 30 days to test it and i don't want to waste it on waiting for him.
i modded a code i found and added:
RewriteCond %{HTTP_HOST} ^[a-z]+_[a-z]+\.(.*) [NC]
RewriteRule ^(.*)$ [%1...] [R=301,NC,L]
this fixed my problems and now everything works fine. my only problem is that the url updates in the bar to www.domain.com/purl.php?purl=fn_ln
but i'm working on that. hopefully i can find that myself w/o help.
but definitely thanks so much for your help. i swear after i pay off my debts and if i still have a job i'll surely donate/subscribe to this site!
To fix the "lost all the links" problem, you will need to modify your pages to link to the correct (sub)domain using canonical links (i.e. including the domain name), instead of using page- or server-relative links.
An alternative would be --as I explained at some length in my post above-- to better-define the "page" URL-space for which this rewriterule is to be applied. As it is now, *all* requests to <fn_ln>.example.com/<anything> are rewritten, and apparently that's not what you really want.
You might be happier if you only rewrote requests for the "home" page of each user subdomain at the exact URL "<fn_ln>.example.com/" and only that exact URL, or alternately, if you *did not* rewrite requests for images, scripts, CSS files, and other included objects. You'll have to decide if the inclusion or exclusion method suits you best, as the correct answer depends on just how your site works now and how you want your site to work.
Jim
my problem with the lost links was b/c the the provided templates didn't point to a direct source. now that that i've relinked them everything works fine.
man i have a lot of learning to do. thank you!