htaccess URL wrong redirection - html

I want to redirect
/about
/about/
/about.html
/about.html/
/weare/
/weare
/weare.html
/weare.html/
All these pages should be redirected to about.html and I want to do this with .htaccess.
I wast trying by
RewriteRule ^(about|weare).*/ about.html [R=Permanent]
This is somewhat working, but not exactly what I want. It is also redirecting some other pages.
I have added as said by ThinkingMonkey
If you want to do a permanent redirect:
RewriteCond %{REQUEST_URI} !^/about\.html$ [NC]
RewriteRule ^(about|weare)(\.html)?/?$ about.html [L,R=301]
This is working But it is going for infinite loop.

Do this:
RewriteRule ^(about|weare)(/|\.html/?)?$ about.html [L]
If you want to do a permanent redirect:
RewriteCond %{REQUEST_URI} !^/about\.html$ [NC]
RewriteRule ^(about|weare)(\.html)?/?$ about.html [L,R=301]

RewriteRule ^((about|weare)(.|/)?(html)?) about.html [NC]

Related

Website uses URLs with www and non-www subdomain which may cause duplicate content and bad links

How can I redirect www to non www for sub-directories? It is OK for home page but for sub-directories, it doesn't work. My sub-directory files have dynamic content.
My .htaccess is:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R]
RewriteRule blog/(.*)/ viewpost.php?page=$1
RewriteRule blog/(.*) catpost.php?page=$1
but it only affects the home page, not sub-directories.

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.

How to redirect website.com/ and website.com/index.php to another page with htaccess

I can redirect website.com/index.php to website.com/home but I can't find a way to redirect website.com to website.com/home
I have tried RewriteRule ^/$ /home [R=301] but it does nothing.
A single rule can handle both redirects:
RewriteRule ^/?(index\.php)?$ /home [NC,L,R=301]
Try this
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?website\.com$ [NC]
RewriteRule .* http://www.website.com/home [R=301,L]
This rule redirects www.website.com to www.website.com/home
Or add this to your .htaccess
RewriteRule ^/?$ /home [R=301,L]

htaccess to redirect main domain

I have a htaccess that redirects my main domain "www.main.com" to "www.main.com/DBS2010".
The htaccess works but my url changes to "www.main.com/DBS2010" can I make the url stay as "www.main.com"?
htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?main.com$
RewriteRule ^(/)?$ DBS2010 [L]
You can try this code for that:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?main\.com$ [NC]
RewriteRule ^$ DBS2010 [L]
This will not change URL in browser to `/DBS2010'.