devilindisguise Posted December 16, 2014 Share Posted December 16, 2014 Hello all Was hoping someone could help. I have a .htaccess file that contains the following: RewriteEngine On RewriteRule ^sites/([a-z0-9]+)/?$ sites.php?letter=$1 [NC,L,QSA] RewriteRule ^network-devices/([a-z0-9]+)/?$ network-devices.php?letter=$1 [NC,L,QSA] RewriteRule ^site/([0-9]+)/?$ site.php?site_id=$1 [NC,L] RewriteRule ^network-device/([0-9]+)/?$ network-device.php?device_id=$1 [NC,L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php?%{QUERY_STRING} The problem I am having is that if I try to restrict access to a page via the following code I get the following error from Chrome: Code: if(!isset($_SESSION['username'])) { header('location: login'); } Chrome Error: This webpage has a redirect loop I also get a similar error on other browsers so leads me to think that something strange is afoot in that .htaccess file. So for example, I can restrict access quite nicely to my index.php page. If I try enter it into my URL I get whisked away to: http://localhost:8888/<SITENAME>/login If I then try to browse to an area of the site called 'sites' I get the loop and see that the URL has now changed to: http://localhost:8888/<SITENAME>/sites/login Pretty sure that it should rather read: http://localhost:8888/<SITENAME>/login Is it immediately obvious to anyone as to what the issue could be?Thank you Link to comment https://forums.phpfreaks.com/topic/293121-htaccess-file-causing-loops/ Share on other sites More sharing options...
requinix Posted December 16, 2014 Share Posted December 16, 2014 Why you're going to /sites/login is straightfoward: you gave the browser the relative location "login" so if you're trying to go to /sites/123 then it will take you to /sites/login. If you went to /sites/123/, with the trailing slash, then you'd be redirected to /sites/123/login. You need an absolute URL in there so you don't have to worry about paths. Link to comment https://forums.phpfreaks.com/topic/293121-htaccess-file-causing-loops/#findComment-1499717 Share on other sites More sharing options...
devilindisguise Posted December 17, 2014 Author Share Posted December 17, 2014 Thanks requinix Apologies for the delay. That works a treat. Absolute URL was what I needed to add. Thanks! Link to comment https://forums.phpfreaks.com/topic/293121-htaccess-file-causing-loops/#findComment-1499816 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.