Welcome to WebmasterWorld Guest from 54.205.251.179

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

php to html redirect problem

   
6:49 am on Aug 13, 2010 (gmt 0)

5+ Year Member



Hi,

I wanna to rewrite all .php extension to .html
I added that code to my htaccess but when i try to html google verification file directly (www.domain.com/googleabcxyz.html), i see 404 page. How can i fix it?

# url rewriting php to html
RewriteRule ^([0-9a-zA-Z-]+).html$ $1.php
RewriteRule ^([0-9a-zA-Z-]+)/([0-9a-zA-Z-]+).html$ $1/$2.php
RewriteRule ^([0-9a-zA-Z-]+)/([0-9a-zA-Z-]+)/([0-9a-zA-Z-]+).html$ $1/$2/$3.php
RewriteRule ^([0-9a-zA-Z-]+)/([0-9a-zA-Z-]+)/([0-9a-zA-Z-]+)/([0-9a-zA-Z-]+).html$ $1/$2/$3/$4.php

Thanks.
11:41 am on Aug 13, 2010 (gmt 0)

5+ Year Member



If you want incoming requests for the .php page to receive the .html page instead, your code is backwards. Using just the first example, it should be

RewriteRule ^([0-9a-zA-Z-]+)\.php$ $1.html

Note the added backslash before the period.

I'd probably try this, though, as more general:

RewriteRule ^(.*)\.php$ $1.html

Can't be sure that's right without testing, but it's a starting point.
6:46 pm on Aug 13, 2010 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



You'll need to add a preceding RewriteCond that excludes requests for the Google file URL from being rewritten to an internal PHP file.

You'll also need a redirect such that if .php URLs are requested, user is redirected to the .html URL instead.

You must add the [L] flag to every rewrite, and the [R=301,L] flags and the target protocol and domain name to every redirect.

[edited by: g1smd at 6:48 pm (utc) on Aug 13, 2010]

6:47 pm on Aug 13, 2010 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



In either case, put a leading slash ahead of $1 if possible.

This is a security consideration.

Jim