Forum Moderators: phranque
.htacess is basicly there to redirect any www call to non-www, 'make' pages extension-less (they are .html with bunch of php includes), handle php files, and don't show directory index file name
As of now
.htaccess in my root is
# Use PHP4 as default
AddHandler application/x-httpd-php4 .php
addhandler application/x-httpd-php .htm .html
DirectoryIndex index.html
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule [^/]$ [%{HTTP_HOST}%{REQUEST_URI}...] [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+/)*([^./]+)/?$ $2.html [L]
and .htaccess in my sub-folders (where indexfolder is replaced with actual folder index file name)
addhandler application/x-httpd-php .htm .html
DirectoryIndex indexfolder.html
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule [^/]$ [%{HTTP_HOST}%{REQUEST_URI}...] [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+/)*([^./]+)/?$ $2.html [L]
I would appreciate another set of eyes looking at this as I am going blind.... :)
When all is said and done, I would like to url to look like
http://example.com/test/testfile
so - www.example.com redirects to example.com/
but www.example.com/test/testfile.html redirects to example.com/test/testfile.html (.html is still visible)
and www.example.com/test/testfile redirects to example.com/test/testfile and gives 404 (proper redirect to non-www but can't 'find' the file)
This is what I got
Options All -Indexes
# Use PHP4 as default
AddHandler application/x-httpd-php4 .php
AddHandler application/x-httpd-php .htm .html
DirectoryIndex index.html
RewriteEngine On
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^example\.com
RewriteRule (.*) http://example.com/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+/)*([^./]+)/?$ $2.html [L]
Any help is appricated
DirectoryIndex index.html
RewriteEngine On
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^example\.com$
RewriteRule (.*) http://example.com/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(([^/]+/)*[^./]+)/?$ /$1.html [L]
I also end-anchored your hostname pattern so that the hostname must be exactly "example.com" with no appended period and/or port number.
Note that in accepting an optional trailing slash, you create duplicate-content. It would be better to redirect if the slash is wrong in any case, rather than accepting either URL. Given the 'emergency' nature of your problem, I doubt you're concerned with that right now... :)
Jim
[edited by: jdMorgan at 3:39 pm (utc) on Sep. 15, 2008]