Hide page filename in href URLs - html

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]

Related

How to remove index.html from url

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

Website links won't work with .htaccess code which removes .html extension

I have the following code in my .htacess file for my website to remove '.html' from my urls and to redirect any .html to the same page without it (example.com/home.html to example.com/home)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [L,R=301]
#301 from example.com/page.html to example.com/page
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/
RewriteRule ^(.*)\.html$ /$1 [R=301,L]
However, when I try to click on links that are pointed to other pages on my website, I get a 404 error.
I've tried setting the href to http://www.example.com/page2, /page2 and more but I still get the same error. Any help?
Please save your code and put only the following code in your main directory .htaccess file :
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/+(.*?/)?(.*?)\.html[\s?/] [NC]
RewriteRule (.*)$ /%1%2 [R=302,L,NE]
Note: clear your browser cache because you did 301 redirect and test the code

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.

Redirecting old .html page to new without html extension page?

I've just changed permalinks in my wordpress site.
And my old links were like that,
http://www.sitename.com/category/postname.html
Now new links are
http://www.sitename.com/category/postname/
I'm getting 404 error at old links, how can i redirect all .html pages to new non .html pages with .htaccess?
In the htaccess file in your document root, add these before your wordpress rules:
RedirectMatch 301 ^/([^/]+)/([^/.]+)\.html$ /$1/$2/
RedirectMatch 301 ^/([^/]+)/([^/]+)/([^/.]+)\.html$ /$1/$2/$3/
Of if you need to limit it by hosts, you can use mod_rewrite:
RewriteCond %{HTTP_HOST} sitename.com [NC]
RewriteRule ^([^/]+)/([^/.]+)\.html$ /$1/$2/ [R=301,L]
RewriteCond %{HTTP_HOST} sitename.com [NC]
RewriteRule ^([^/]+)/([^/]+)/([^/.]+)\.html$ /$1/$2/$3/ [R=301,L]
In the htaccess file, just put:
Redirect 301 /postname.html http://www.sitename.com/category/postname/
The accepted answer (above) from Jon Lin caused some issues for me.
This is my result, which works well, and is a bit more compact.
It works for both, with and without directories in the path.
Oneliner:
RedirectMatch 301 ^/(.*)\.html$ /$1
Or if you need it limited by host:
RewriteCond %{HTTP_HOST} myDomain.com [NC]
RewriteRule ^(.*)\.html$ /$1 [R=301,L]
Example: