htaccess redirect to subdir
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Help with my Plusnet services
- :
- Everything else
- :
- htaccess redirect to subdir
htaccess redirect to subdir
30-04-2014 11:01 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
In /public/.htaccess I have
RewriteEngine on
# www.gtsagedev.co.uk to point to gtsagedev dir
RewriteCond %{HTTP_HOST} ^www.gtsagedev.co.uk$ [nc]
RewriteRule (.*) /gtsagedev/$1
but I'm getting 500 Internal server error
When I comment out these lines, www.gtsagedev.co.uk/gtsagedev/index.php works fine.
What have I got wrong?
Re: htaccess redirect to subdir
30-04-2014 11:14 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
RewriteEngine on
RewriteCond %{HTTP:Host} ^(?:www.gtsagedev.co.uk)?$
RewriteCond %{REQUEST_URI} !^/gtsagedev/
RewriteRule ^(.*) /gtsagedev/$1 [NC,L,NS]
I make no claims to be a mod rewrite expert and I'm not 100% on what each of the above expressions is doing but it seems to work for me. If any part of it's unnecessary or not quite right then I'm sure somebody will be along to correct me shortly

Bob Pullen
Plusnet Product Team
If I've been helpful then please give thanks ⤵
Re: htaccess redirect to subdir
30-04-2014 11:33 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Strictly backslashes are needed in the host string to make the full stops into real ones.
This is similar to Bob's (but using the correct HTTP_HOST) and should work *
RewriteEngine on
# Point domain to /gtsagedev folder
RewriteCond %{HTTP_HOST} ^www\.gtsagedev\.co\.uk$ [NC]
RewriteCond %{REQUEST_URI} !^/gtsagedev/
RewriteRule (.*) gtsagedev/$1
Edit: but apparently doesn't - see reply #7

Re: htaccess redirect to subdir
30-04-2014 12:08 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator

Apologies for the naivety but this really isn't my forté

Bob Pullen
Plusnet Product Team
If I've been helpful then please give thanks ⤵
Re: htaccess redirect to subdir
30-04-2014 12:45 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
I *think* yours applies for 0 or 1 occurrence of the domain string, in effect anything though I'm not entirely sure of this.
I use the style of my post for a domain in my own .htaccess though checking back that also has RewriteBase /
Within the voodoo of mod_rewrite I'm stuck on whether that is significant at the moment.
David
Re: htaccess redirect to subdir
30-04-2014 12:47 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
RewriteCond %{HTTP_HOST} ^([^.]+\.)?yourdomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/cgi-bin/
RewriteCond %{REQUEST_URI} !^/yoursite/
RewriteRule (.*) /yoursite/$1
Link.
Don't need to turn on the rewrite engine again.
Gabe
Re: htaccess redirect to subdir
30-04-2014 1:13 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
I'll stick to my own directives at the moment as they're doing what I want them to do. I don't think I can wildcard the subdomain because I've different subdomains under the same domain pointing to different folders.
Bob Pullen
Plusnet Product Team
If I've been helpful then please give thanks ⤵
Re: htaccess redirect to subdir
30-04-2014 4:02 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Now all I need to do is to remove the spurious gtsagedev in the address url's (eg. http://www.gtsagedev.co.uk/gtsagedev/index.php/contact-me), but I vaguely remember how to do that - will update when I have!
Update: It's in the Joomla configuration.php live_site$ variable. (Yes, I'm running Joomla...)
Re: htaccess redirect to subdir
30-04-2014 5:04 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Re: htaccess redirect to subdir
30-04-2014 5:18 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Quote from: spraxyt RewriteRule (.*) gtsagedev/$1
needs to be
RewriteRule (.*) /gtsagedev/$1
when in .htaccess. In conf it's without the leading slash.
Gabe
Re: htaccess redirect to subdir
01-05-2014 12:29 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator

Re: htaccess redirect to subdir
01-05-2014 1:30 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Anyway, it's all working as I want now, so thanks again.
Re: htaccess redirect to subdir
01-05-2014 6:10 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Quote from: spraxyt I think having RewriteBase / in my .htaccess (for other reasons) makes my relative path work.
Yup, that'll do it. If you have a leading slash though, it'll work with or without the rewritebase. Apart from that, the main difference between your recipe and Bob's is that Bob's condition matches either the stated host or an empty host header (not just anything), which could be useful if a request without a host header could ever reach your rewrite, but in this context it can't, so I'm not sure it is.
Gabe
Re: htaccess redirect to subdir
18-05-2014 6:21 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Due to a change in file structure I now need to redirect all historical links for my site to a subdirectory called 'catalog', but I am having the same problem as the first poster.
I cannot seem to resolve it with any of the suggestions above.
I have built a .php website on the Hostopia server This is linked as a sub-domain of my main html site. This cgi site is to replace an earlier site that didn't use the 'catalog' directory, so now anybody trying an old link gets a 'page not found' message.
So I want all links to the old site to be redirected to the same path as before, but within the 'catalog' directory.
I can redirect specific files eg Index.php, but can't find the code to redirect all traffic for the other web pages in the same way.
I just can't get it to work - I must be missing something, can anybody advise please?
Pedro C
Re: htaccess redirect to subdir
18-05-2014 9:10 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Could you post a .htaccess file example that works for an index.php file? Forum members would then be better placed to advise on generalising the rule.
David
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Help with my Plusnet services
- :
- Everything else
- :
- htaccess redirect to subdir