Kevan Posted December 12, 2005 Posted December 12, 2005 Hi, new guy here learning his way, taking over site work. I want to enter into my browser address: www.my-domain.com/anyword and have the server use anyword as a base to look for files with extensions? e.g. anyword.html, anyword.htm, anyword.php etc. I do not want to create an entry for every file I might have. I also want to use that approach in my page href=links if possible. The main goal is to make it easier to change file names in the future /application.html today might be /application.php next year. or I could upload about.html and test it on my own while existing visitors still view about.htm. Getting search engines to see the new ??.html is an redirection issue for later. I know that a >DirectIndex statement in the .htaccess file controls the search order for default pages. if the client enters www.domain.com the server will look for index.html index.htm .... default.htm. This would be similar except looking for files. Thanks for any ideas and thanks for being here to read this. Kevan Quote
TCH-Andy Posted December 12, 2005 Posted December 12, 2005 Hi Kevan, welcome to the forums I use; >#RewriteEngine on RewriteBase / # parse out basename, but remember the fact RewriteRule ^(.*)\.htm$ $1 [NC,E=WasHTM:yes] # rewrite to document.php if exists RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.*)$ $1.php [R=301,S=1] # else reverse the previous basename cutout RewriteCond %{ENV:WasHTM} ^yes$ RewriteRule ^(.*)$ $1.htm to check if the php file exists, if not use the htm file. I'm sure that could be modified to perform what you are after, if you know which file type you are using to start with. Others might have better ideas Quote
Kevan Posted December 12, 2005 Author Posted December 12, 2005 (edited) I use; >#RewriteEngine on RewriteBase / # parse out basename, but remember the fact RewriteRule ^(.*)\.htm$ $1 [NC,E=WasHTM:yes] # rewrite to document.php if exists RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.*)$ $1.php [R=301,S=1] # else reverse the previous basename cutout RewriteCond %{ENV:WasHTM} ^yes$ RewriteRule ^(.*)$ $1.htm to check if the php file exists, if not use the htm file. I'm sure that could be modified to perform what you are after, if you know which file type you are using to start with. Others might have better ideas So this example would take (for example) about.htm and rename it to about.php only if about.php existed? Otherwise it puts about.htm back? I'll see what I can do. Thanks Edited December 12, 2005 by Kevan Quote
TCH-Andy Posted December 12, 2005 Posted December 12, 2005 So this example would take (for example) about.htm and rename it to about.php only if about.php existed? Otherwise it puts about.htm back? I'll see what I can do. Thanks That's correct. That way, if neither the php nor the htm exist, you will get a 404 error that the file has not been found. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.