|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Removing file extension
I tried Googling this but none of them fit my liking. Basically in the root directory of my site, (public_html) I have all my files. I have index.html, contact.html, about.html, portfolio.html and articles.html. I would like help on removing the file extension. One that will allow me to go to (for example)
www.devwebsites.com/about.html and remove the .html and display the code from about.html. And alternately if I type in www.devwebsites.com/about it should return the code from about.html, but not show about.html in the URL bar. I need this to work with other files such as contact.html, etc.. I hope I explained my problem good enough.. Thanks.
__________________
"Quality of responses may vary. I reserve the right to change my mind for any reason what-so-ever without admitting I was wrong. I'd prefer to change your mind however, it's easier on my ego". - jwdonahue |
|
#2
|
||||
|
||||
|
Just in case you wanted to see my attempt. Here is my entire .htaccess file{
Code:
ErrorDocument 404 /404.html
RewriteEngine On
RewriteCond %{HTTP_HOST} ^devwebsites.com [NC]
RewriteRule ^(.*)$ http://www.devwebsites.com/$1 [L,R=301]
RewriteCond %{REQUEST_URI}!(\.[^./]+)$
RewriteCond %{REQUEST_fileNAME}!-d
RewriteCond %{REQUEST_fileNAME}!-f
RewriteRule (.*) /$1.html [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+html\ HTTP
RewriteRule ^(.+)\.html$ http://www.devwebsites.com/$1 [R=301,L]
|
|
#3
|
||||
|
||||
|
Last edited by requinix : June 28th, 2009 at 08:56 PM. Reason: added a link |
|
#4
|
||||
|
||||
|
Hi,
I am not sure what that is supposed to mean. Could you expand on that? I found a guywith the same question on me here: http://www.webmasterworld.com/apache/3371997.htm. Problem is their code didn't work for me. 500 error ![]() |
|
#5
|
||||
|
||||
|
(I edited a link into my post)
It does exactly what you want: you can link to /about and Apache will automatically serve up about.html. If you add that Option to your .htaccess then you can use links without the extension - so long as the extension has been registered somewhere - like with AddType. If it gets a request for /foo, Apache will look (if the file/directory doesn't exist) for /foo.* where the * is any extension it knows about: html, php, jpg... By the way, Code:
RewriteCond %{REQUEST_URI} !(\.[^./]+)$
RewriteCond %{REQUEST_fileNAME} !-d
RewriteCond %{REQUEST_fileNAME} !-f
It's missing the spaces. |
|
#6
|
||||
|
||||
|
Yea, it does look like it will do what I want. However, I just fixed the space issue, and now it works like I want. Redirects if I add .html on the end, and works perfectly. Thanks requinix!
![]() |
![]() |
| Viewing: Dev Shed Forums > System Administration > Apache Development > Removing file extension |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|