Jump to content

Recommended Posts

Posted

Hi, new guy here learning his way, taking over site work. :lol2:

 

 

:lol: 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

Posted

Hi Kevan,

 

welcome to the forums :lol2:

 

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

Posted (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 by Kevan
Posted
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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...