Forum Moderators: phranque
My question is, what has to be enabled on the hosts side to make it work? I tried all the codes, and none of them work, probably because something on the hosts side isnt set up for this.
I have cPanel, with a subdomain moduel. Do i simply try to make a * subdomain? Is there something specific i need to ask my host to do?
Thanks in advance
Basically my users have a blog at mysite.com/journal?user=name, and i want them to access it by going to name.mysite.com
heres the code im using, but no matter what subdomain i enter, it just takes me to the home page
RewriteCond %{HTTP_HOST}!^(www\.)?mysite\.com [NC]
RewriteCond %{HTTP_HOST} ^(.+)\.mysite\.com [NC]
RewriteRule .* /journal?user=%1 [R=301,L]
Can anyone help?
RewriteCond %{REQUEST_URI}!^/journal?user=
RewriteCond %{HTTP_HOST}!^www\.(mysite\.com)
RewriteCond %{HTTP_HOST} ^([a-z][a-z0-9_-]+[a-z0-9])\.(mysite\.com)
RewriteRule (.*) /journal?user=%1/$1 [L]
it worked for smoeone else..
Yes, ask them to add ServerAliases of "<yourdomain>.com" and "*.<yourdomain>.com" to your VirtualHost container. They may be happy to do it, or refuse -- no way to know ahead of time. The first alias will fix your problem with the www-less domain, and you also need "wildcard subdomains" defined at both the DNS and virtual server level.
You basically want to point all subdomains to the *same* place in the filesystem that your www subdomain now points to. Then you can use your mod_rewrite code to move the subdomain name into a query parameter and call your script. This generally cannot be done using a "Control Panel" because they are almost always set up to point each subdomain to a unique subdirectory.
The most common cause of 500-Server Errors when copying code from this forum is that the forum posting cleanup code removes spaces preceding "!" characters. For example, the code you posted in msg#2 should be:
RewriteCond %{HTTP_HOST} !^(www\.)?mysite\.com [NC]
RewriteCond %{HTTP_HOST} ^([^\]+)\.mysite\.com [NC]
RewriteRule .* /journal?user=%1 [R=301,L]
The second code snippet does not look like it would work to me; query strings are not available in the server REQUEST_URI variable.
Jim
RewriteRule .* /journal?user=%1 [L]
Jim
I dont know if something else might be interfering, so heres my whole htaccess file..
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
<FilesMatch "^[^\.]+$">
ForceType application/x-httpd-php
</FilesMatch>
RewriteCond %{HTTP_HOST}!^(www\.)?example\.com [NC]
RewriteCond %{HTTP_HOST} ^([^\]+)\.example\.com [NC]
RewriteRule .* /journal?user=%1 [L]
DirectoryIndex index.html.var index.htm index.html index.php index
php_value register_globals Off
php_value track_vars On
php_value arg_separator.output "&"
php_value arg_separator.input "&"
RewriteCond %{HTTP_HOST}!^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\. [NC]
RewriteRule ^$ /journal?user=%1 [L]
Now i just have to figure out the rest of the urls, for example
changing www.example.com/journal?user=myname&view=pictures
to
myname.example.com/pictures
I'll try to figure it out on my own, but if anyone can come up with a solution before me, i'll appreciate it :)
The problem now is when i try to view an individual picture. The url is normally www.mysite.com/journal?user=myname&view=pictures&pic=file.jpg
So i thought the following code would work, but it doesnt.
RewriteCond %{HTTP_HOST}!^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\. [NC]
RewriteRule ^pictures/pic/([a-z_0-9]+)/$ /journal?user=%1&view=pictures&pic=$1 [L]
So the url myname.mysite.com/pictures/pic/file.jpg should work, but i get the error associated with the username not being registered, which is confusing to me.. because myname.mysite.com works, and myname.mysite.com/pictures works..
Im stumped on this one.. Anyone see what im doing wrong?
Also, if you wish to use a pattern in the rule that can match the destination URL, you will need to explicitly exclude that URL to avoid rewrite 'looping':
# Add one of the two following RewriteConds to prevent
# looping, whichever seems more appropriate
RewriteCond %{REQUEST_URI} !^/journal
RewriteCond %{QUERY_STRING} !user=.
#
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\. [NC]
RewriteRule .* /journal?user=%1 [b][QSA,[/b]L]