With the help of a few DP members I've got an htaccess that does what I need. It changes: domain.com/subdomain/ to subdomain.domain.com BUT it breaks when somebody simply enters (without the trailing slash): domain.com/subdomain Could somebody please let me know how to fix this? Options +FollowSymLinks RewriteEngine On # this takes care of the subdomain - but doesn't work without a trailing slash RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ RewriteRule ^(.*)$ http://subdomain.domain.com/$1? [R=301,L] # this does something unrelated to the problem RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule ^([^/.]+)/?$ index.php?s=$1 [QSA,L] Code (markup):
Hello kerosene, I have fixed this type of issues many times and to me it seems like problem lies in your VirtualHost entry for subdomain, please edit VirtualHost in httpd.conf. Modify following directives for VirtualHost for your subdomain ServerName subdomain.domain.com ServerAlias subddomain.domain.com www.subdomain.domain.com and then just move your current .htaccess file and try to browse. Regards,
I'm encountering pretty much the same issue if someone can help with my problem too. I am attempting to use .htaccess in order to redirect from the DocumentRoot path (/) to a sub-path (/app/webroot). My /.htaccess file appears as follows: RewriteEngine on RewriteRule ^$ app/webroot/ [L] RewriteRule (.*) app/webroot/$1 [L] Code (markup): And my /app/webroot/.htaccess file appears as follows: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php?url=$1 [QSA,L] Code (markup): Let's say I have folder "/app/webroot/img". Typing this URL (with trailing slash) works: http://domain/img/ Code (markup): However, typing in this URL (without trailing slash): http://domain/img Code (markup): ...ends up redirecting me (and changing the URL in the browser) to this: http://domain/app/webroot/img/ Code (markup): I'm clueless after playing with both .htaccess files for hours, as I've only had limited .htaccess experience. Any help is appreciated!
Hello mhuggins, Well you will have to modify your VirtualHost in this case, if you do not have access to modify httpd.conf then ask your Host to modify it as provided below. ServerName domainname.com At this moment it must be something like ServerName www.domainname.com or if it is addon domain then in ServerName it must be ServerName subdomain.domainname.com so it is not able to pickup URL without trailing slash, please ask them to modify it to ServerName domainname.com and everything should get sorted. Regards,
Hi eukvps, This is an addon domain on my HostGator account. Am I correct in my understanding that I need to have HostGator change FROM "ServerName www.domainname.com" TO "ServerName domainname.com" within httpd.conf? Sorry for my naivety on the topic, and thanks for the help!
Hi again If it as addon domain then, it should be ServerName subdomain.domainname.com Please ask HostGator to change it to ServerName www.addondomainname.com or ServerName addondomainname.com That should solve your case Regards,
Thanks again, I really appreciate it. I hope this works. I've been going at this for hours, and I thought I was close at one point with this: # Force trailing slash on directories RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^(.+[^/])$ $1/ [R,L] Code (markup): Unfortunately, that only worked on one directory and not others, and I don't know why...
Hmm, this above directive actually seems to work correctly for all directories that have no file matching the DirectoryIndex value (i.e. the index of files within the directory will be displayed). Conversely, my "blog" directory (which includes an index.php file) still encounters my original problem. I figure that "blog" is not being considered as a directory, and is thus not matching the -d directive of RewriteCond. However, I simply tried adding the following line alone, and it still didn't work, causing me much confusion: RewriteRule ^/blog$ /blog/ [R,L] Code (markup):
Well I had HostGator change it as per eukvps' suggestion, but that didn't make any difference. If anyone has any suggestions, I'd appreciate it. I think my last message in this thread was on the right track, but I don't know where to go from here.