Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Silverstripe trailing slashes breaks login


Reply

3 Posts   745 Views

Avatar
Midnightraven

2 June 2011 at 6:16am Community Member, 2 Posts

Hi, I've been asked to updated the .htaccess file on a website to always add trailing slashes onto the URLs, e.g.
"www.xyz.co.uk/news" -> "www.xyz.co.uk/news/"

I added this code to my htaccess file on the apache web server:

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

This is working really well, except that with these rules, when I attempt to login to Silverstripe "www.xyz.com/admin", when I input my (correct) user name & password, Silverstripe responds with "That doesn't seem to be the right e-mail address or password. Please try again".

I am having trouble identifying where the login is getting disrupted. I would be grateful for any advice on an additional rule/tweak that would allow the admin login to function correctly.
Regards,
AndyH.

Avatar
simon_w

2 June 2011 at 8:36am Forum Moderator, 474 Posts

Your RewriteRule will include POST requests, so submitting the login form to /Security/LoginForm will get redirected to /Security/LoginForm/ and turned into a GET. You should add a condition to your rule so that it excludes POST requests.

Avatar
Midnightraven

3 June 2011 at 4:04am Community Member, 2 Posts

Ahh, I see. Thank you, I understand the logic of the login process better now.

For other peoples reference, these are the updated htaccess rules:
RewriteCond %{THE_REQUEST} !^POST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.xyz.co.uk/$1/ [L,R=301]

Thanks.