rnmcd Posted October 16, 2007 Share Posted October 16, 2007 How do you get a directory to point to a file? For example: How would I get www.mywebsite.com/directory to point/direct to www.mywebsite.com/file.html Thanks. Quote Link to comment Share on other sites More sharing options...
TCH-Kate Posted October 16, 2007 Share Posted October 16, 2007 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 Quote Link to comment Share on other sites More sharing options...
click Posted October 16, 2007 Share Posted October 16, 2007 Add the following to .htaccess file >RewriteEngine On RewriteRule ^directory/?$ file.html [NC] Quote Link to comment Share on other sites More sharing options...
SteveW Posted October 16, 2007 Share Posted October 16, 2007 (edited) 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 October 16, 2007 by SteveW Quote Link to comment Share on other sites More sharing options...
click Posted October 16, 2007 Share Posted October 16, 2007 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 Quote Link to comment Share on other sites More sharing options...
rnmcd Posted October 16, 2007 Author Share Posted October 16, 2007 It is possible to specify several pages:DirectoryIndex index.shtml index.php index.php3 index.html index.htm Do you mean that it is possible to use any of those page names or that the DirectoryIndex can be redirected to several pages? Quote Link to comment Share on other sites More sharing options...
TCH-Dick Posted October 16, 2007 Share Posted October 16, 2007 (edited) 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 October 16, 2007 by TCH-Dick added note Quote Link to comment Share on other sites More sharing options...
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.