Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,194,842 members, 7,956,167 topics. Date: Monday, 23 September 2024 at 06:38 AM

Webmasters Quiz :: How To Fix Apache Redirection Bugs - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Webmasters Quiz :: How To Fix Apache Redirection Bugs (1139 Views)

Solution To Nairaland Redirection Problem On Etisalat / Dhtml Quiz: How Will You Detect If A Browser Support Javascript From Php Code? / Next Quiz: How Do You Detect With Php If Javascript Has Been Turned Off? (2) (3) (4)

(1) (Reply) (Go Down)

Webmasters Quiz :: How To Fix Apache Redirection Bugs by Nobody: 7:39pm On Apr 01, 2012
Lets assume you have a website like www..net running on a linux server, and you somehow have
these two files on your root

index.php
index.htm

meanwhile, the server will use .htm by default followed by .php if .htm does not exist.

And you want the website to use .php by default, what are the possible ways of solving this problem?
- I know there are multiple ways to solve this problem (obtrusively and unobtrusively e.g. .htaccess, jscript redirect,server config),
let us see how you would solve the problem - specifics are required here.
Re: Webmasters Quiz :: How To Fix Apache Redirection Bugs by Slyr0x: 8:56pm On Apr 01, 2012
.htaccess

RewriteEngine on
RewriteRule index\.htm index.php [NC,R]
Re: Webmasters Quiz :: How To Fix Apache Redirection Bugs by netesy(m): 9:36pm On Apr 01, 2012
Learning************
Re: Webmasters Quiz :: How To Fix Apache Redirection Bugs by DualCore1: 6:54am On Apr 02, 2012
Slyr0x: .htaccess

RewriteEngine on
RewriteRule index\.htm index.php [NC,R]

Is there any reason why you escaped the . literal on the left hand side and didnt escape it on the right?
I used to think it was mandatory to escape literals in regular expression (just like in PHP) but it doesn't seem mandatory in this. Infact I was thinking escaping literals in this case won't work.

Netesy, we learn everyday smiley
Re: Webmasters Quiz :: How To Fix Apache Redirection Bugs by Nobody: 7:27am On Apr 02, 2012
That .htaccess method is very much different from the one i use. But this works just fine.
Any volunteer for the jscript way?
Re: Webmasters Quiz :: How To Fix Apache Redirection Bugs by DualCore1: 10:46am On Apr 02, 2012
*dhtml:
Any volunteer for the jscript way?
windows.location
Re: Webmasters Quiz :: How To Fix Apache Redirection Bugs by Slyr0x: 6:42pm On Apr 02, 2012
Dual Core:

Is there any reason why you escaped the . literal on the left hand side and didnt escape it on the right?

.htaccess

RewriteEngine on
RewriteRule index\.htm index.php [NC,R]

From the little I know, the "\" which is the escape character is always used to escape dots as dots have a special meaning in regular expressions. .but what we have on the right(in this case) is the direct URL and NOT a regular expression and as such, it gets parsed that way.

Explaining further, in the example below, what we have on the right is a regular expression and as such, it needs to be escaped. Noticed the difference?

RewriteEngine On
RewriteCond %{HTTP_HOST} !^my-domain\.com$ [NC]

Also, I think you should read this http://www.rankinglabs.com/Mod_Rewrite

It explains the difference between RewriteRule (Left Side) and RewriteRule (Right Side)
Re: Webmasters Quiz :: How To Fix Apache Redirection Bugs by Slyr0x: 6:52pm On Apr 02, 2012
Dual Core:
windows.location

Put this in the index.htm header

<head>
<title></title>
<script type="text/javascript">window.location="index.php";</script>
</head>
Re: Webmasters Quiz :: How To Fix Apache Redirection Bugs by Nobody: 7:39pm On Apr 02, 2012
Yeah, now the scenario in which i was working was tougher because the index.php actually embeds the index.htm,
so i had to go if(location.href.indexOf('index.php')==-1) {location="index.php";} - got that eh?
Re: Webmasters Quiz :: How To Fix Apache Redirection Bugs by DualCore1: 9:00pm On Apr 02, 2012
Thanks for the explanation slyr0x, dunno what I was thinking to expect escapes on the RHS. I did a test just now and fixed my confusion about escaping literals.
Re: Webmasters Quiz :: How To Fix Apache Redirection Bugs by omni1: 6:25am On Apr 07, 2012
*dhtml:
Lets assume you have a website like www..net running on a linux server, and you somehow have
these two files on your root

index.php
index.htm

meanwhile, the server will use .htm by default followed by .php if .htm does not exist.

And you want the website to use .php by default, what are the possible ways of solving this problem?
- I know there are multiple ways to solve this problem (obtrusively and unobtrusively e.g. .htaccess, jscript redirect,server config),
let us see how you would solve the problem - specifics are required here.

Who's got the server config solution if any
Re: Webmasters Quiz :: How To Fix Apache Redirection Bugs by DualCore1: 7:34am On Apr 07, 2012
Omni, since HTML is clientside and can't access the server then there can't be a serverside solution, apart from the .httaccess config.
Re: Webmasters Quiz :: How To Fix Apache Redirection Bugs by Nobody: 7:55am On Apr 07, 2012
Dual Core: Omni, since HTML is clientside and can't access the server then there can't be a serverside solution, apart from the .httaccess config.
Exactly, so the solution can either be from server(htaccess), server configuration - to use index.php as preference for .htm,
or client - sided = like the javascript solution we spoke about.

(1) (Reply)

Joomla Error: Ssl-error-rx-record-too-long-and-apache-ssl / Get Free 1000 Daily Traffic To Your Website / I Port My Hobby Website To Wordpress. Have A Look

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 16
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.