Forum Moderators: phranque

Message Too Old, No Replies

Rewriting a login URL to /login/ with trailing slash

         

Mike521

10:27 pm on Feb 2, 2012 (gmt 0)

10+ Year Member



I'm trying to rewrite my login URL to /login/. The first part is working fine, if you go to example.com/login/ you see my login page. But if you go to example.com/login you get an error

I tried doing a 301 redirect from /login to /login/ but it generated a redirect loop. I also tried setting example.com/login to show the login page, which worked but then I had two working URLs - example.com/login and example.com/login/ which I don't like. Is there an easy way to make sure the trailing slash is always appended?

g1smd

10:33 pm on Feb 2, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



See the Apache
DirectorySlash
directive.

DirectoryIndex
allows you to omit the index filename from your links.

Mike521

2:06 pm on Feb 3, 2012 (gmt 0)

10+ Year Member



no luck with directoryslash, I suspect because login is not really a directory. Same for directoryindex, since it's not a directory there's no index

I guess there's no way to do it then?

penders

2:35 pm on Feb 3, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If "login" is not a real directory then presumably you are doing an internal rewrite to the actual location?

Mike521

2:44 pm on Feb 3, 2012 (gmt 0)

10+ Year Member



yes exactly, that's what I meant when I said I'm rewriting my login URL to /login/. The real location is totally different

g1smd

9:41 pm on Feb 3, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What you wanted to do in the original post is quite achievable for virtual URLs.

Let's see your code. There's probably quite a simple error in it to fix.

Mike521

7:41 pm on Feb 8, 2012 (gmt 0)

10+ Year Member



Sorry I took so long to get back to you g1smd, here's the code:

RewriteCond %{REQUEST_URI} ^/login/[NC]
RewriteRule (.*) /mm5/merchant.mvc?Screen=LOGN [QSA,L]

g1smd

9:21 pm on Feb 8, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I would suggest using example.com/login as the URL and redirecting requests for example.com/login/ to URL without trailing slash.

There's a thread about that only yesterday: [webmasterworld.com...]

Mike521

7:51 pm on Feb 9, 2012 (gmt 0)

10+ Year Member



perfect timing, ok I'll give that a shot, thanks for the help!