Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mod_rewrite redirect 301

Status
Not open for further replies.

mickjbud

Programmer
Jun 13, 2002
48
GB
Hi all

I am using mod_rewrite to tidy up the urls and to hide the php extension of the files. I have now renamed a few of the files and would like to inform the engines(Google) that the file is now permanent.

The problem I am having is that I wish for the new file name to be shown in the url but with the html extension as apposed to the php extension.

The original file is foo_old_file.php
the new file is foo_new_file.php I want the url in the address to read foo_new_file.html which doesn't exist.

The code I am using is

RewriteRule ^foo_old_file\.(php|html)$ [nc]

RewriteRule ^/?(.*).html$ $1.php

The url in the address reads .

The last rule obviously changes the extension. If I only include the filename and not the full URL then it just shows the orignal file name. If I put the rule after the extension rewrite rule it doesnt find the file (again obviously)

I have not included the permanent switches as I am only testing at this stage.

Also the urls are examples.

Any help is appreciated.

TIA

Mick

mymapofseychelles
eWOC
LookandBookIt
Rotography
 
It sounds like you might want the [R=301] modifier, which means "redirect with a 301 HTTP code", which subsequently means "permanently moved" ... like so:

Code:
RewriteRule ^foo_old_file\.(php|html)$ [URL unfurl="true"]http://www.myurl.com/foo_new_file.html[/URL] [nc,R=301]

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

Also note that I've added a backslash in front of the ".html" in your second rule. Without it, you'd match any character there; with it, you match only the literal period.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top