Saurabh Khirwal
Saurabh Khirwal

Reputation: 341

better way to write this mod_rewrite?

I am currently using this type of mod_rewrite code for all my page...but i think its too long. There must be a shorter way of writing same code? and does it increase any kind of load on he server?

RewriteRule ^Login/$ login.php [L]
RewriteRule ^login/$ login.php [L]
RewriteRule ^Login$ login.php [L]
RewriteRule ^login$ login.php [L]

the first line is for normal url - "http://website/Login/"
second one is if the user doesn't type the capital "L" - "http://website/login/"
third one is if he doesn't add an ending slash on the first url - "http://website/Login"
fourth one is if he doesn't add an ending slash on the second url - "http://website/login"

Upvotes: 0

Views: 49

Answers (4)

osoner
osoner

Reputation: 2415

RewriteRule ^login/?$ login.php [L,NC]

Should do it. NC is for case insensitivity and ? makes the slash optional.

Upvotes: 0

nitro2k01
nitro2k01

Reputation: 7745

For example:

RewriteRule ^[Ll]ogin/?$ login.php [L]

But I must ask, why?? Why not simply choose one URL and stick with it? Do you expect people to enter the URL manually?

Upvotes: 0

Ben Everard
Ben Everard

Reputation: 13804

Further to @milan's answer, you could also specify the NC flag, of which makes the rewrite rule not case sensitive.

RewriteRule ^login/?$ login.php [NC,L]

Reference

Upvotes: 2

milan
milan

Reputation: 12412

Try this regex:

^[Ll]ogin/?$

[Ll] matches either L or l, question mark means the previous character (slash) is optional.

Upvotes: 2

Related Questions