1

I am using .htaccess file for rewriting the url's in my php based project. I have written some rules to rewrite the url accordingly. However i was facing problem while writing url for log-in.php with 4 different cases. My current rules are as follows:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#Home Pages rule#
RewriteRule ^home index.php [L]
RewriteRule ^contact-support contact-support.php [L]

#Login Rule#
RewriteRule ^login log-in.php [L]
RewriteRule ^login/([0-9]+)$ log-in.php?temporaryBookingId=$1 [L]
RewriteRule ^login/([0-9]+)/([0-9]+)$ log-in.php?temporaryBookingId=$1&jSessionId=$2 [L]
RewriteRule ^login/([0-9]+)/([0-9]+)/([a-zA-Z]+)$ log-in.php?temporaryBookingId=$1&jSessionId=$2&name=$3 [L]

For the current rules cases are like 1. When there is no parameter in the url then it should open the login page by default. 2. When there are parameters, the login page after filling login credentiials should redirect accordingly. 3. When parameter in the url exceeds the required limit then it must show the page 404 page not found

The bottleneck coming here is that I have written the rule to allow the parametric urls up to 2 only i.e. for temporaryBookingId & jSessionId & name. The url will work like

http://example.com/login/1234/1234/sagar

but when I add more parameters here like

http://example.com/login/1234/1234/sagar/1234/1234

it should show me 404 not found error page but it is opening the same page again. Here if I comment rule RewriteRule ^login log-in.php [L] then the above condition works & shows me error page but then if i open simple login page it navigates me back to 404 not found error page. How the rule for log-in.php page to be written in order to satisfy all the conditions?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Shaggie
  • 1,799
  • 7
  • 34
  • 63
  • Is this the exact #Login Rule# you have in your .htaccess file ? Why Im asking is because in #Login Rule#, the third RewriteRule misses the '?' for the substituion file **login.php?**, which is used to concatenate the query string with url – Vijay Wilson Aug 08 '16 at 12:10
  • Thanks for your reply. Let me tell you that from #Login Rule# i have written rules as per my required conditions. The first rule is applied when i am opening the log-in.php page without any parameter in the address bar – Shaggie Aug 08 '16 at 12:14
  • Ya i got your point actually the time i copied and was setting it in the edit section, it was removed by mistake. I have corrected it – Shaggie Aug 08 '16 at 12:16
  • Why dont you try this, comment all the other RewriteRules except this **RewriteRule ^login log-in.php [L]** for #Login Rule#. Now pass url parameter like **http://domain.com/login/1234** and check if the url redirects to the original file if it works then it shows that your rewrite rules are not working accordingly – Vijay Wilson Aug 08 '16 at 12:20
  • yes it is working there!. it is another problem. Can you tell the exact way to deal with this?? – Shaggie Aug 08 '16 at 12:33
  • 2
    '$' end of the pattern is missing in **RewriteRule ^login log-in.php [L]**. Add it and try – Vijay Wilson Aug 08 '16 at 12:38
  • you are right!. Thanks – Shaggie Aug 08 '16 at 12:44
  • @Maktwick you might find this answer useful: http://stackoverflow.com/a/19309893/727208 – tereško Sep 01 '16 at 20:41

0 Answers0