Jump to content

Directory Pointing To File


rnmcd
 Share

Recommended Posts

Hello

Please name the file as index.html or index.htm.That will automatically open that page when you access the url www.mywebsite.com/directory

If you want to use a diffrent page create a .htaccess file inside the directory and To change the page that will be displayed when a visitor access a directory, write:

DirectoryIndex <necessary page>

It is possible to specify several pages:

DirectoryIndex index.shtml index.php index.php3 index.html index.htm

Link to comment
Share on other sites

In your public_html/.htaccess, I think it will be something like this. It's a starting point, anyway:

 

#only necessary if you haven't already turned it on

RewriteEngine On

 

RewriteCond %{REQUEST_FILENAME} ^.*/directory.*$ [NC]

RewriteRule ^.*$ http://www.mywebsite.com/file.html [R=301,L]

 

This would rewrite all requests for all pages in (and below) /directory to the single file file.html.

 

There is a potential problem if you have any other directories with names that start the same as directory such as directory1, directory2, etc. It would rewrite them all, and preventing it doing so would require more code.

 

If you create an .htaccess IN /directory, it's even simpler, since no tests (RewriteCond) need to be applied at all:

 

RewriteRule ^.*$ http://www.mywebsite.com/file.html [R=301,L]

 

------

 

Heh, others beat me to it. There are differences in how each of the methods will function.

Mine sends a notification back to the browser that the old address is now invalid, "now, and from now on, please request this different page instead".

 

click's serves the alternate page, but I think it does not tell the browser that the old page is obsolete.

 

One is a rewrite and the other is a redirect, but at the moment I'm drawing a blank on which is which.

Edited by SteveW
Link to comment
Share on other sites

Yeah, busy around here all of a sudden.

 

SteveW's rewrite rule will redirect the browser and the visitor will see the new address in their browser. The [R=301] tells it to redirect. Use this if a page has been moved. Without the [R] flag, the server will serve file.html but /directory/ will still show in the visitor's browser -- there is no indication to the visitor that the request has been redirected. Choose whichever behavior you're after

Link to comment
Share on other sites

Do you mean that it is possible to use any of those page names or that the DirectoryIndex can be redirected to several pages?

 

It means it sets the order of precedence for the main page the web server should serve up from a directory. Therefore, if the first listed file file does not exist then it would move on to the next file. In the case of our servers we are running Apache and the standard config would like like:

>DirectoryIndex index.html index.htm index.shtml index.xhtml index.wml index.perl index.pl index.plx index.ppl index.cgi index.jsp index.js index.jp index.php4 index.php3 index.php index.phtml default.htm default.html home.htm

 

Using rewrite rules will work but really are unneccesarry for your situation. You will want to override the default settings by adding the following to your htaccess for a specific directory:

>DirectoryIndex file.html

 

If you want to use the same file as the default for all directories, then add the same line above to your htaccess in /public_html.

 

NOTE: Don't dismiss the rewrite options completetly. I was only addressing the DirectoryIndex option and assuming you are not moving or changing an existing page.

Edited by TCH-Dick
added note
Link to comment
Share on other sites

Join the conversation

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

Guest
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.

 Share

×
×
  • Create New...