Forum Moderators: phranque

Message Too Old, No Replies

find and replace all extensions in file names

         

hermes

11:37 pm on Jun 29, 2006 (gmt 0)

10+ Year Member



Q1) I would like to change all the .html terms in my file titles to .php So, I would like to do find and replace in file titles. I have Dreamweaver and this can do find and replace in the actual files - but cannot do it in the actual file titles. What can I do?

Q2) I would like to change all the links in my files from .html to .php

BUT I only want to change the internal links for my website - I do not want to change the outbound
external links. So, I want to change:

www.mydomain.com/variable_here.html
to www.mydomain.com/variable_here.php

BUT NOT change in any way:

www.externaldomain.com/variable_here.html

I guess to do this I need some regular expression that can make the distinction between:

mydomain.com/variable_here.html
and externaldomain.com/variable_here.html

But what form would such a regular expression take in dreamweaver? HOw can I account that
"variable_here" can vary in length and characters? I have looked in the Dreamweaver documentation but am a bit stumped.

jatar_k

1:49 am on Jun 30, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



why are you changing the extension at all?

just enable php parsing for the html extension. Changing filenames is always a bad idea, it means you have to get competely reindexed.

there are ways to do this using grep and the likes but if you miss one, trouble. Or if you make a mistake, even worse.

vincevincevince

2:05 am on Jun 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is not tested but should work...

At the top:


<?php ob_start();?>

At the bottom:


<?php
$page=ob_get_clean();
//All lines with NO domain name
$page=preg_replace("/(href\=\"[^\: ]*?).html/ism","$1.php",$page);
//All lines with YOUR domain name
$yourdomain="http://www.widgets.foo";
$page=preg_replace("/(".preg_quote($yourdomain)."[^ ]*?).html/ism","$1.php",$page);
header("Content-length: ".strlen($page));
print $page;
?>

hermes

2:32 am on Jun 30, 2006 (gmt 0)

10+ Year Member



Why I need change the extensions - its just something that I have to do. If you are interested - its because I have the same problem as this guy - and having .php instead of .html solves it.

[webmasterworld.com...]

I think Grep is unix only. IS there any windows tools i can use?

I dont understand the second post. What is that php code for? Sorry m8 for my lack of insight.

jatar_k

2:43 am on Jun 30, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



doesn't dreamweaver have multi file find and replace?

the code above is some php code that should do what you want

hermes

2:49 am on Jun 30, 2006 (gmt 0)

10+ Year Member



dreamweaver can only do find and replace INSIDE files. It cannot do find and replace with file NAMES.

Altho would be great if I am wrong. But think i not.

vincevincevince

3:00 am on Jun 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



second post

Put it around each page and it will do the replacement on the fly.

If you want to do it 'one off' then download sed for win32. Easy to find if you Google.

You should be able to tar everything then run sed on the tar.

hermes

3:23 am on Jun 30, 2006 (gmt 0)

10+ Year Member



But that option cannot change the fileNAMES. (or can it?)

hermes

3:29 am on Jun 30, 2006 (gmt 0)

10+ Year Member



An email I just sent to some friends - clarifies what I am trying to do somewhat:

do u guys no of any tool that can do "find and replace" in fileNAMES? so in the actual filenames - not in the files themselves. I need to change the extension on thousands of files but just too many to do manually.

tedster

6:50 am on Jun 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do a search on a phrase like "rename many files" or "rename multiple files". You'll find a lot of offerings, some of them freeware. I was just looking at one freeware app called "1-4a Rename" that offers a one click approach for changing extensions.

However, I still don't understand why you don't enable php parsing for the html extension, as jatar_k suggested. Changing all your urls is like going back to square one with all the search engines.

TerryG

9:38 am on Jun 30, 2006 (gmt 0)

10+ Year Member



Try this
[funduc.com...]
it has a search and replace i have used for years

Barb

4:38 am on Jul 1, 2006 (gmt 0)

10+ Year Member



Can someone please detail this "php parsing"?

I think I may need to "change" my html pages to php due to the shopping cart I am using. My html pages are informational pages that I had already created prior to using the cart (osc) and I've been reading that mixing the cart's php pages with the site's hmtl pages will cause sessions problems for the customer.

It has always been my limited understanding that once you place one little snippet of php code in a html page, you have to rename the page ext from .html to .php.

Does this php parsing eliminate that need? How does it work and what does it involve to implement it?

Thanks in advance

tedster

6:04 pm on Jul 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's one of several threads on the topic:
[webmasterworld.com...]

Barb

8:46 pm on Jul 1, 2006 (gmt 0)

10+ Year Member



Thanks Tedster! :-)

hermes

3:51 am on Jul 3, 2006 (gmt 0)

10+ Year Member



SO. I have done the 1st part of this task - I have managed to change all the filenames from .html to .php BRILLIANT!

But I am still unable to do the second part:

--------

I would like to change all the links in my files from .html to .php

BUT I only want to change the internal links for my website - I do not want to change the outbound
external links. So, I want to change:

www.mydomain.com/variable_here.html
to www.mydomain.com/variable_here.php

BUT NOT change in any way:

www.externaldomain.com/variable_here.html

I guess to do this I need some regular expression that can make the distinction between:

mydomain.com/variable_here.html
and externaldomain.com/variable_here.html

But what form would such a regular expression take in dreamweaver? HOw can I account that
"variable_here" can vary in length and characters? I have looked in the Dreamweaver documentation but am a bit stumped.

----------

Can anyone help?

hermes

4:38 am on Jul 3, 2006 (gmt 0)

10+ Year Member



got this done now. surprised myself.