I have a website currently where there is www.website.com/about.html
.
However if I type www.website.com/about/
into the url, it comes up with the default error 404 page.
I have seen somewhere something about editing the htaccess file but that is something I am not sure how to do.
Just add this line at the top of your htaccess to make your URLs extension less:
Options +MultiViews
OR else if you prefer mod_rewrite
then use this code in your DOCUMENT_ROOT/.htaccess
file:
RewriteEngine On
# To externally redirect /dir/file.html to /dir/file
RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.html[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
# To internally forward /dir/file to /dir/file.html
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule ^(.+?)/?$ /$1.html [L]
/about/
Is a directory. Which on a server will call for the index.* file in that dir to be served.
Either call /about.html directly. Or (more elagantly) put an index.* (can be html php whatever) into /about/ instead.
www.website.com/about.html
is reffering for a file named as about.html
stored on the root folder of your application.
when you try to access the www.website.com/about/
it means you are trying to access a file in a folder named "about" in your application. Which you don't have it in your solution and you gets an error.
So the way you are accessing it is wrong.
Try the following code for removing .html and access the file you are trying to access
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [L,R=301]
As you want to remove .html from your application url so no need to write .html in your navigating links eg,
<a href="http://www.website.com/about">about</a>
As anubhava mentioned, you can add this line at the top of your .htaccess file to make your URLs extension less: Options +MultiViews
However you still have to access it as
www.website.com/about
because with
www.website.com/about/
you are going to the about directory instead. Hope this helps.
You need to make changes in Apache config file for this. This question already answered here: How to remove .html from URL
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.