How to remove index.html from url - html

I have uploaded my HTML files to my website. Now i need to find a way to redirect users to a Home.html page when they enters www.mywebsite.com
i have tried to to this in htaccess but it did not work, i am not sure if it is correct
RewriteEngine On
#if request is mywebsite.co.uk/something OR
RewriteCond %{HTTP_HOST} ^mywebsite\.co.uk$ [OR]
# or www. mywebsite.co.uk/something
RewriteCond %{HTTP_HOST} ^www\.mywebsite\.co.uk$
# but not mywebsite.co.uk/Home.html
RewriteCond %{REQUEST_URI} !^/Home.html/
#change it to mywebsite.co.uk/Home.html/something
RewriteRule (.*) /Home.html/$1 [R=301]

Remove your code and put this only # .haccess file :
DirectoryIndex Home.html

Make sure the .htaccess file is in the directory where you want to change the index.html file

Related

.htaccess: remove .html and redirect slash version

On my site, all pages have .html extension and are directly off the root (i.e., site.com/page.html). I've successfully used the following .htaccess code to make .html not show:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
This gives me a url like site.com/page, but in the event that a user links to or visits the url using a slash (i.e., site.com/page/), I'd like to 301 redirect to the non-slash version.
I'm having trouble integrating this part into the above code. Thanks in advance for any suggestions.
Try to something like this
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.example.com/$1/ [L,R=301]

Show index.html when they go to /admin/*

I'm looking for a solutions for the following:
When they go to subdomain.domain.be or subdomain.domain.be/admin or subdomain.domain.be/admin/something I want them to see the index.html in the root of my subdomain.
How can I do this with htaccess?
I've tried this in my .htaccess: Redirect 301 /admin/* /index.html . But that doesn't do anything. Also tried this: Redirect 301 /admin/* /index.html but then I get index.htmlsomething ...
How can I fix this?
UPDATE:
My .htaccess file looks like this:
Options -Indexes
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^admin/(*.)$ /index.html [L]
Try the following code
RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdomain.domain.be$
RewriteCond %{REQUEST_URI} ^/$ [OR]
RewriteCond %{REQUEST_URI} ^/admin
RewriteRule ^ /index.html [L,R]
Try this:
RewriteRule ^admin/(*.)$ /index.html [L]
And see the documentation.
Put index.html in the root of subdomain.domain.be and it should display automatically.
If not, try DirectoryIndex index.html.

redirect subfolder to root with <subfolder-name>.html using htaccess

I have website that has links like
domain-name.com/pages/contact-us/
www.domain-name.com/pages/contact-us/
domain-name.com/pages/about-us/
www.domain-name.com/pages/about-us/
and other pages ...
What I'm looking for how i can redirect them permanently to same subfoldername.html using htaccess . for example for all the links above should redirected to
domain-name.com/contact-us.html
www.domain-name.com/contact-us.html
domain-name.com/about-us.html
www.domain-name.com/about-us.html
also for other pages, otherwise if page not found to root index.html .
Thanks in advance.
Try the following
RewriteEngine On
RewriteCond %{REQUEST_URI} ^(/pages/(.*[^/])/?)$
RewriteRule ^(.*)$ /%2.html [L,R=302]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.html [L,R=302]
The first three lines will remove the folder pages. If there is a trailing slash, it will be removed. The last three lines will redirect to /index.html, if the request file does not exist.

Hide page filename in href URLs

I configured htaccess file in root folder of Apache htdocs like
DirectoryIndex index.py
And when you open this page there is href:
<h3><a href='/?id=blah'><font color='8650AC'>blah</font></a></h3>
When clicked on, it sends me to
http://127.0.0.1/index.py?id=blah
instead of
http://127.0.0.1/?id=blah
as I want. How to fix this issue?
Try adding this line in the same .htaccess:
DirectoryIndex index.py
RewriteEngine On
# remove index.php
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} /index\.py [NC]
RewriteRule ^(.*?)index\.py$ /$1 [L,R=302,NC,NE]

Access CSS file after htaccess modified url

I am using this htaccess file to re-write my urls:
RewriteEngine On
# Friend SEO url
#RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /([^\ ]+)\.php
#RewriteRule ^ /%2/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/(.*?)/?$
RewriteCond %{DOCUMENT_ROOT}/%1.php -f
RewriteRule ^ /%1.php [L]
The url rewriting works perfectly fine (for example, mypage/web-store/ can be used instead of mypage/web-store.html).
The problem however, is that my rewritten url can't retrieve the CSS file correctly. If I use the normal url however, I have no problem at all because the CSS file is in a subfolder of mypage. But with the url rewrite, it looks for the css file inside the folder /web-store/, which doesn't exist...
Anyone knows a way to counter this ?
You need to either change your URLs to absolute URLs (add a leading /) or you can set a relative URL base in the header of your pages:
<base href="http://example.com/mypage/" />
Where "example.com" is the domain name of your site and the /mypage/ is where the css is at.
If all else still fails, you can try to rewrite the proper page:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ([^/]+\.css)$ /path/to/styles/$1 [L,R=301]