Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have rewrite rule that works okay, but ends up changing the visible URL if a trailing slash is omitted when going to an index.php:

RewriteEngine on
RewriteCond  %{REQUEST_URI} !main
RewriteRule /.* /~user/main$0

When someone visits

The page works fine. However, if they visit

They are redirected to

This still works fine, but I'd rather have the URL not change. The server has other configuration that allows for ~user in the URL to take you to public_html on the disc (where these files are located). So the actual URL should be:

But it still leaves my name in the domain. I'm not sure if I am even able to solve this problem, but I'm also not sure what other configuration could cause it.

share|improve this question

You can always use mod_rewrite to append a trailing slash

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$$1/ [L,R=301]

Add it above your first rule

share|improve this answer

The above rules is not the cause of it. Check all the included configuration files in conf.d (or similar). If you set AllowOverride All, find all the .htaccess files with:

find /path/to/document/root -name .htaccess

and take a look at that.

I also suggest you turning on the mod_rewrite log:

RewriteLog /tmp/rewrite.log
RewriteLogLevel 9

to see how the URI is parsed.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.