views:

46

answers:

2

Hi There,

I'm re-writing a subdomain to a 'folder' - actually a page in wordpress, and this all seems to be working correctly. I don't want the address in the URL bar to change though.

Everything works fine unless the user does not put a trailing slash after the page name, then the page is still redirected to the correct URL but the URL in the address bar changes

For example: foo.example.com/bar Becomes: public.example.com/foo/bar

Where : foo.example.com/bar/ stays at the correct URL in the address bar but shows the redirected page (this is correct)

What rule do i need to add to add in a trailing slash if its not sent?

The code i have so far is:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

Options +FollowSymlinks

RewriteCond %{HTTP_HOST} ^foo\.example\.com$ [NC]
RewriteRule ^(.*)$ http://public.example.com/foo/$1 [P]

# rules for WordPress ...

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

#####

</IfModule>

Any help would be fantastic, I'm pretty new to htaccess. Thanks!

A: 

This rule should do it:

RewriteRule .*[^/]$ %{REQUEST_URI}/

Put this rule in front of your other rules. You also may want to add a condition to exclude existing files:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .*[^/]$ %{REQUEST_URI}/
Gumbo
Thanks Gumbo, unfortunately i get a 500 server error with that line. Tried it in a few places and no joy :(. Thanks for your help though!
Andy Smart
@Andy Smart: And what does the error log file say?
Gumbo
Error log is saying: Request exceeded the limit of 10 internal redirects due to probable configuration error.
Andy Smart
A: 

Phew, after a bit of playing around i seem to have got it working:

RewriteCond %{HTTP_HOST} ^foo\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://foo.example.com/$1/ [L,R=301]

RewriteCond %{HTTP_HOST} ^foo\.example\.com$ [NC]
RewriteRule ^(.*)$ http://public.example.com/foo/$1 [P]

Basically, the first block adds a trailing slash to the URL is it's not there in the first place, then the second block does the proxy redirect for the URL.

As far as i can see this catches all cases, but let me know if there are any gaping holes!

Andy Smart