Forum Moderators: phranque
[test.mysite.com...]
it DOESN'T work, while:
[test.mysite.com...] (with trailing slash)
does. This is true for any sub directory underneath the subdomain. I've asked both the hosts of the domain and subdomain, but they each just kick the problem back and forth.
Can I set up a .htaccess file on the subdomain so it detects and redirects any sub directories with no trailing slashes to the exact URL but with a slash? I figured that's easier than to figure out what the problem might be DNS wise.
Thanks!
George
The simple answer to your question is... Yes.
The slightly longer answer (to the question I am sure you will have next: How?) depends on what your actual structure is now.
Is your site only 2 levels deep (/yoursite.com/dir/) or are there more levels?
Do you have requests that end in file extensions (/dir/file.html) or are they all simply /dir/file or /dir/file/. (The ruleset you will need to use will varry depending on this)
Are you using any rewrites now?
Hope this helps.
Justin
1) It's possible some directories will be more than 2 levels deep, though I'd be happy right now with a solution that deals just with one level (ie: test.mysite.com/dir) if it's more difficult the other way around.
2) Yes, there will be actual file requests, whether it's pages (ie: test.mysite.com/file.html) or images etc.
The server is WHM/ cPanel based, and I've gotten mod_rewrite working as far as fighting hot linking.
Thanks!
George
Since you are using only 1 level, this should be close to what you need:
RewriteEngine ON
RewriteRule ^([a-z]+)$ /$1/ [R=301,L]
As long as your files are all letters, this should catch the file name, but eliminate files, because the regular expression only matches letters, not any .(dot) characters. By putting the 'hard' ending prior to matching any / character, anything that contains a / should also fail to match.
I looked at another version with conditions, but it seemed like it would waste more processor overhead... It's a little late where I am, so if my logic is failing (IOW your rule doesn't work) please, let me know and I will have another look at it when I am a little more fresh.
Hope this helps.
Justin
RewriteCond %{REQUEST_URI} !^[^.]*/$
RewriteRule (.+) /$1/ [R=301,L]
Test cases:
GET / -- no redirect because path ends with / (this also fails to match the RewriteRule pattern in .htaccess context)
GET /subdir/ -- no redirect, because path ends with /
GET /index.html -- no redirect, because path contains "."
GET /subdir/index.php -- no redirect, because path contains "."
GET /subdir/index.cgi/ -- no redirect, because path contains "." and ends with /
GET /subdir -- redirect, because path contains no "." and does not end with /
GET /subdir/subdir -- redirect, because path contains no "." and does not end with /
Jim
A new question- as mentioned, my subdomain test.mysite.com is created by adding a A record to the DNS Zone of Server A, so it looks something like:
test A Record 12.12.12.12
where "12.12.12.12" is the IP of server B actually hosting test.mysite.com Do I need to add another A record like so:
www.test A Record 12.12.12.12
So [test.mysite.com...] also works? I think non slash URLs are being redirected to this URL instead. Thanks,
Why do you think that is happening? -- Do you have code that does this? (It won't happen by magic)
If you want "www.example.com" to resolve, yes, you will need an A record.
All of the code above assumes that you already have other mod_rewrite code working in the same file. If not, it's possible you may need to add:
Options +FollowSymLinks
RewriteEngine on
Jim