Forum Moderators: phranque

Message Too Old, No Replies

Changing extensionless php files to html

         

Lorel

6:27 pm on Apr 22, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm working on a site that had files written in extensionless php. I changed them to html and want to set up extensionless html files. I assume because they were "hidden" I just need to set it up for html?

I read the guide in the library but don't see this mentioned there. Can someone tell me how to do this?

g1smd

7:15 pm on Apr 22, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Files on the servers have extensions. URLs used out on the web don't need extensions.

URLs and files are not the same thing.

It is the action of a server, and in this case the action of a rewrite, to connect a URL request to a file inside the server.



This example code connects an extensionless request to a file inside the server:

RewriteRule ^([a-z0-9]+)$ /$1.php [L]

RewriteRule ^([^\.]+)$ /$1.php [L]



I have no idea what you mean by "hidden".

Lorel

8:05 pm on Apr 22, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi Gs1

This example code connects an extensionless request to a file inside the server:

RewriteRule ^([a-z0-9]+)$ /$1.php [L]

RewriteRule ^([^\.]+)$ /$1.php [L]

I have no idea what you mean by "hidden"
.

Sorry, i'm not a programmer and not familiar with all the terminology, although I mostly understand what is occuring in htaccess (take all files from A-Z or any number and make requested changes.

What I'm wanting is for the page to look like the following files (even though the files actually have .html on the end) so sometime in the future they can be changed to something else without setting 301s for every page (like I've done in the past causing a delay in ranking). I don't write .php so I changed them to .html .

www.example.com/
www.example.com/about
www.example.com/products

Is this the correct to set this up?

RewriteRule ^([a-z0-9]+)$ /$1.html [L]

RewriteRule ^([^\.]+)$ /$1.html [L]

jdMorgan

12:29 am on Apr 23, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Again, files must have file extensions. URLs need not.

This code doesn't change URLs or filenames, it maps or "points" an incoming URL-path request from a client (e.g. a browser) to a different-from-usual filepath inside the server.

RewriteRule ^([a-z0-9]+)$ /$1.html [L]

translates to "When the client requests a URL-path composed of one or more letters and/or numbers, prepend the value of DocumentRoot and a slash, append ".html", and serve the file at the resulting filesystem location."

If that's what you want, then the code is fine.

The second variant differs only in that the pattern recognizes "one or more characters not equal to a period." Note that using this pattern will mean that you can never use a period in a (sub)directory-path. This may be of no concern to you at present, but consider this in light of your long-term plans.

Note also that it is not necessary to escape periods within alternate groups, so "[^.]" will do just fine instead of "[^\.]".

Jim

Lorel

2:34 pm on Apr 23, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks JD