2

I am having some trouble hiding the .html extensions on my website. I am running on WampServer with Apache V.2.2.22. rewrite_module is active and i have changed the httpd.conf file to have AllowOverride all

This is the only htaccess file that i know of and this is all it contains...

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC]
RewriteRule ^ %1 [R=301,L,NC]
</IfModule>

Its not working and i don't know why... here is my httpd.conf file

DocumentRoot "c:/wamp/www/"

<Directory />
    Options FollowSymLinks
    AllowOverride all
    Order deny,allow
    Deny from all
</Directory>

<Directory "c:/wamp/www/">
    Options Indexes FollowSymLinks
    AllowOverride all

#   onlineoffline tag - don't remove
    Order Allow,Deny
    Allow from all

</Directory>

and this is where i have placed the .htaccess file...

E:\wamp\www\DesktopVersion\.htaccess

Any suggestions as to why this is not working would be great!

EDIT: Just to clarify This is the correct .htaccess code to use... Complement of 'anubhava'

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC]
RewriteRule ^ %1 [R=301,L]

RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [L]
</IfModule>
ChristopherStrydom
  • 7,338
  • 5
  • 21
  • 34
  • As long as you have a second Directory block that sets `Allow Override All` for your web root (and the files you are accessing are in that folder not the main root) the `Allow Override None` on the root (/) will not be a problem. Have you tried your htaccess file with the tags removed? Would be nice to know if it is just getting bypassed because it is failing this test. – Sarah Kemp Feb 19 '13 at 17:36
  • Hi thanks for the comment. I wasn't to sure what you meant so i added more of the httpd.conf file to my question. Also i have changed the version of Apache to the latest. If you could re-read my question to see if there is anything wrong that would be great. Thanks a Bunch, Chris `Edit: I tried to take the Tags out and still nothing` :/ – ChristopherStrydom Feb 21 '13 at 00:58
  • Can you put some junk in your htaccess file and check if you get a 500 response as suggested in the answer to this question (http://stackoverflow.com/questions/9234289/verify-if-htaccess-file-is-running), to verify that your htaccess file is being used? – Sarah Kemp Feb 21 '13 at 16:09
  • Okay i did that and i did get the 500 error so it is reading the file... Now what? – ChristopherStrydom Feb 21 '13 at 18:35
  • When you say that this code doesn't work, do you mean you are typing, say `www.mysite.com/index.html` and it is not changing to `www.mysite.com/index`? Or that when you go to `www.mysite.com/index` it gives you a 404? – Sarah Kemp Feb 21 '13 at 21:07
  • its not changing to www.mysite.com/index ... BTW i have changed back to Apache 2.2.22 – ChristopherStrydom Feb 22 '13 at 18:00

1 Answers1

4

You should append this code in your .htaccess:

# To externally redirect /dir/foo.html to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC]
RewriteRule ^ %1 [R=301,L]

# To internally forward /dir/foo to /dir/foo.html
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [L]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • i tried that but it gave me the 500 error? The weird thing is once i tied this and then reverted back; the original code worked? Cheers anyway seem to have fixed my problem somehow :L – ChristopherStrydom Feb 22 '13 at 18:15
  • aww damm its not working in the other browsers... Now what to do? your code seemed to work as it got rid of the .html at the end but then it gave a 500 error ? – ChristopherStrydom Feb 22 '13 at 19:06
  • Paste your latest .htaccess in your question then I can suggest you what to fix there. – anubhava Feb 22 '13 at 19:25
  • Okay got it, I didn't ask you to delete your existing Rewrite code (that's why I wrote **append**). You need your existing rules as well. – anubhava Feb 22 '13 at 20:02
  • Oh right sorry for the misunderstanding..The new answer works perfectly! Thank you very much for the help – ChristopherStrydom Feb 22 '13 at 21:06
  • Hi again... i was just wondering if it were possible for me to change my web address to 1 word? For example my address is http://oracle/DesktopVersion/New.html but i would like it just to be 'oracle' i am on a home server/network – ChristopherStrydom Feb 22 '13 at 22:49
  • APPEND this rule in the end: `RewriteRule ^$ /DesktopVersion/New.html [L]` – anubhava Feb 23 '13 at 04:10