.php -> .html inside a directory

Discuss practical ways rearrange URLs using mod_rewrite.

.php -> .html inside a directory

Postby BMN » Wed Jun 02, 2010 2:08 pm

hello
I have no idea how to force mod rewrite to change pages with .php extension to .html
The thing is not that simple, as I redirect visitors to certain directory inside public_html (root dir).
Normally I'd upload my website to /public_html, as it's the root directory, but I made a /public_html/website dir and uploaded there whole content.
It looks like this:
Code: Select all
Options +FollowSymLinks
RewriteEngine On
#redirecting non www to www
RewriteCond %{HTTP_HOST} ^(my-domain\.pl)$
RewriteRule ^(.*)$ http://www.%1%{REQUEST_URI} [R=301,L]
#redirecting to website dir
RewriteCond %{REQUEST_URI} !^/website/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /website/$1
RewriteCond %{HTTP_HOST} ^(www.)?www.my-domain.pl$
RewriteRule ^(/)?$ website/ [L]

Above rules gives me nice website under
http://www.my-website.pl/pages/example-page.php
And I can still access any data I have in other dirs in /public_html
(that's why I didn't want to use RewriteBase /website )

Now when I try to redirect .php to .html using:
Code: Select all
RewriteRule ^(.*)\.php$ $1.html [R=301,L]

URL looks like that:
http://www.my-website.pl/website/pages/example-site.php/example-site.html

Will above redirect work as supposed only if I use Rewritebase to set "website" dir as the root dir ?

ps. I tried to put above rewrite rule inside "website" dir, but it's far away from working, and shows:
http://www.my-website.pl/home/mysuername/domains/my-website.pl/public_html/website/pages/example-page.html
BMN
 
Posts: 39
Joined: Wed Jul 05, 2006 2:15 am

Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest

cron