homepage Welcome to WebmasterWorld Guest from 54.167.174.90
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
php to html redirect problem
uggur



 
Msg#: 4186355 posted 6:49 am on Aug 13, 2010 (gmt 0)

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.

 

SteveWh

5+ Year Member



 
Msg#: 4186355 posted 11:41 am on Aug 13, 2010 (gmt 0)

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.

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4186355 posted 6:46 pm on Aug 13, 2010 (gmt 0)

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]

jdMorgan

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



 
Msg#: 4186355 posted 6:47 pm on Aug 13, 2010 (gmt 0)

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

This is a security consideration.

Jim

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved