Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database connection error when forcing trailing slashes in .htaccess #16

Open
brettdewoody opened this issue Sep 6, 2012 · 2 comments

Comments

@brettdewoody
Copy link

Thanks for the great addition to the EE community!

I'm having an issue when I try to force trailing slashes using some .htaccess rules. When I add the appropriate rules I get an error of:

A Database Error Occurred
Unable to connect to your database server using the provided settings.

Filename: core/EE_Config.php

Line Number: 211

The error only occurs when I try to access a URL that doesn't have a trailing slash. When I do that I get redirected to appropriate URL (with a trailing slash) but on port 7080. Example:

If I try to access:

http://mydomain.com/something/else

I get redirected to:

http://mydomain.com:7080/something/else/

And then the database error is shown.

Here are the .htaccess rules I'm using for removing the trailing slashes:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule ^(.*)$ $1/ [L,R=301]

If I remove those 3 lines everything works fine.

Also, I'm currently working on the site using dedicated IP address instead of the final domain name. So that might have something to do with it, but I'm not entirely sure.

Have you encountered this before?

@erikreagan
Copy link
Member

Hey Brett

Thanks for the great addition to the EE community!

You bet! Thanks for the appreciation :)

I'm having an issue when I try to force trailing slashes using some .htaccess rules. ... Have you encountered this before?

No, I can't say I have.

The primary issue is that you're matching an environment on a specific IP address and your .htaccess rule is redirecting to the IP plus port number which fails on the PHP switch statement. Why you're getting redirected there - I can't say. Your redirect match is somewhat odd though, can you try being a bit more "loose" in your match? Give this a try if you can:

# Make sure it's not a directory root
RewriteCond %{REQUEST_FILENAME} !-d
# Catch any+all characters and throw a slash in as the last character
RewriteCond %{REQUEST_URI} ^(.+)/$
# Redirect to same URI sans trailing slash (and use 301 for SEO goodness)
RewriteRule ^(.+)/$  /$1 [R=301,L]

Can you give that a shot?

@erikreagan
Copy link
Member

@brettdewoody - just wanted to ping you on this to see if you'd been notified by GitHub about my reply. I'm not familiar enough with how GitHub does email notifications.

Erik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants