Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm using Apache 2.4, and I set up two virtual directories. One requires SSL, and the other one redirects to it.

If a user attempts to visit https://www.derp.com/derp without /derp existing, they correctly get a 404. But when a user visits http://www.derp.com/derp, Apache incorrectly redirects the user to https://www.derp.comderp, removing the slash between the path and the domain name.

I have no idea what would be causing this.

The following is the setup of my Virtual Host.

<VirtualHost *:443>
    ServerAdmin derp@derp.com
    ServerName www.derp.com
    ServerAlias derp.com
    DocumentRoot "C:\Users\derp\Documents\Web Projects\derp"
    SSLEngine on
    SSLCertificateFile "C:\Apache24\certs\cert.cer"
    SSLCertificateKeyFile "C:\Apache24\certs\key.key"
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin derp@derp.com
    ServerName www.derp.com
    ServerAlias derp.com
    Redirect permanent / https://www.derp.com/
</VirtualHost>

<Directory "C:\Users\derp\Documents\Web Projects\derp">
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Require all granted
    SSLRequireSSL
</Directory>

Why would Apache be behaving this way?

Bonus Question: Should redirects be handled in my virtual host definition, or should it be handled in the .htaccess file in the web site's physical directory?

Edit:

I'm starting a Laravel project, and by default the public folder does contain a .htaccess file, so here's that guy:

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

Edit Two:

I tried:

  • adding a slash at the end of the DirectoryRoot path
  • replacing the backslashes with forward slashes in the DirectoryRoot path
  • replacing the backslashes with double backslashes in the DirectoryRoot path

I also removed the .htaccess file from the directory completely.

It redirects correctly when you go from http://www.derp.com to https://www.derp.com. It's just when you specify a path and attempt https that it removes the slash between the domain and the path.

Edit Three:

I also attempted the following suggestion:

Redirect permanent / https://www.derp.com/

Try

RedirectMatch permanent /(.*) https://www.derp.com/$1

or

RedirectMatch permanent (.*) https://www.derp.com/$1

... and instead of redirecting to https://www.derp.comderp, it instead does not redirect, attempts and gives a 404 for http://www.derp.com/derp, but using Apache's 404, instead of throwing a Not Found Exception, as Laravel does without configuration.

share|improve this question
    
The config you provided isn't doing that, you probably have a RewriteRule elsewhere doing redirecting as well? Can you provide the contents of that .htaccess? –  Shane Madden Nov 17 '13 at 9:01
    
Thanks Shane. I threw the contents of that file up there. –  Zaemz Nov 17 '13 at 11:06

1 Answer 1

Your .htaccess for Laravel looks off. It seems like just a simple .htaccess for SEF/SEO friendly URLs I assume. So instead of it being this:

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

Try this instead:

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>
share|improve this answer
    
Unfortunately, that didn't solve the issue either. :( –  Zaemz Nov 17 '13 at 20:55
    
You know - I just came back to read this. Could you explain those changes a little more in depth? –  Zaemz Nov 24 '13 at 5:45

Your Answer

 
discard

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.