Iqlas Uddin
Iqlas Uddin

Reputation: 187

.htaccess not redirecting properly on webhost

I have a website http://alburoojschool.org and this is the .htaccess file :

DirectoryIndex home.php index.php
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule home home.php

RewriteRule ^pages/([^\.]+)$ $1.php
RewriteRule ^news-list/([^\.]+)$ news-list.php?id=$1
RewriteRule ^iq-admin/([^\.]+)$ iq-admin/$1.php
RewriteRule ^news/([0-9]+)/([A-Za-z0-9-]+)/?$ latest-news.php?id=$1&post=$2 [NC,L]
RewriteRule ^events-list/([^\.]+)$ events-list.php?id=$1
RewriteRule ^events/([0-9]+)/([A-Za-z0-9-]+)/?$ upcoming-events.php?id=$1&post=$2 [NC,L]

when I click on http://alburoojschool.org/news-list/1, it says it's a redirect loop but works fine on localhost. Please help me.

Upvotes: 1

Views: 50

Answers (2)

anubhava
anubhava

Reputation: 784998

You need to place this line on top of your .htaccess:

Options -MultiViews

Option MultiViews is used by Apache's content negotiation module that runs before mod_rewrite and makes Apache server match extensions of files. So /file can be in URL but it will serve /file.php.

Upvotes: 1

CD001
CD001

Reputation: 8472

I can see a few potential pitfalls but I think this is your main culprit.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule home home.php

You probably want to ensure that home is a complete phrase and redirect relative to the document root like this:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^home/?$ /home.php

With what you've got an URL like /news-list/home will hit that first match and attempt to redirect to /news-list/home.php which, I'm assuming, doesn't exist so it'll attempt to redirect (again) to /news-list/home.php and so on.

You should probably update all your redirects so that they're relative to the docroot.

Upvotes: 0

Related Questions