How Can I Remove .html with Mod_reWrite?

Discuss practical ways rearrange URLs using mod_rewrite.

How Can I Remove .html with Mod_reWrite?

Postby i-CONICA » Fri Aug 29, 2008 3:40 am

Hi,

I want to be able to remove .htm and .ssi extentions from the urls of my site and replace them with either, nothing or a /

Is this possible?

Thank You. For any advice you've got! :D
i-CONICA
 
Posts: 13
Joined: Tue Aug 26, 2008 9:24 pm

Postby richardk » Fri Aug 29, 2008 8:52 am

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule ^(.*[^/])/?$ /$1.html [QSA,L]

RewriteCond %{DOCUMENT_ROOT}/$1.ssi -f
RewriteRule ^(.*[^/])/?$ /$1.ssi [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby i-CONICA » Fri Aug 29, 2008 11:42 am

Wow Thanks Richard, I will!

I presume i change .html for .htm? Because my page extentions are actually .htm not .html

Where do i put this? Does it have to go in the root of that domain or can i put it where ever i want that to be in effect?

Thanks so much Richard!
i-CONICA
 
Posts: 13
Joined: Tue Aug 26, 2008 9:24 pm

Postby i-CONICA » Fri Aug 29, 2008 11:59 am

I tried that, It didn't work... There was no change to the urls...

:(

Have I done something wrong?
i-CONICA
 
Posts: 13
Joined: Tue Aug 26, 2008 9:24 pm

Postby richardk » Fri Aug 29, 2008 2:34 pm

I presume i change .html for .htm? Because my page extentions are actually .htm not .htm

Yes.

Where do i put this? Does it have to go in the root of that domain or can i put it where ever i want that to be in effect?

Yes, it was written to go in your document root.

The following should work anywhere
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{REQUEST_URI} ^(/.*[^/])/?$
RewriteCond %{DOCUMENT_ROOT}%1.htm -f
RewriteRule ^.*[^/]/?$ %1.htm [QSA,L]

RewriteCond %{REQUEST_URI} ^(/.*[^/])/?$
RewriteCond %{DOCUMENT_ROOT}%1.ssi -f
RewriteRule ^.*[^/]/?$ %1.ssi [QSA,L]


There was no change to the urls...

Mod_rewrite does not change the links outputted by your script or HTML page. What happens when you go to a file without the extension?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 22 guests

cron