URL Rewrite htaccess from root to subfolder - .htaccess

I have a simple home page (index.html) which has a hyperlink to a subfolder named as main which contains index.html. You can witness the same at: rajiviyer.in
Code for hyperlink:
<p>Go to sub folder page - Main</p>
How to configure .htaccess for this so, that I can directly access http://site_name/main/*.html?

You can do this with PHP:
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.domain.de/main");
header("Connection: close");
?>
Or, like you actually want it, with a .htaccess entry:
RewriteEngine On
Redirect 301 / http://www.domain.de/main

Given your comment, please try the below instead:
Options +FollowSymLinks -Multiviews
# Set default page for a directory to index.php
DirectoryIndex index.php index.html
# Turn on the rewrite engine for this override
RewriteEngine On
# Force www.
RewriteCond %{HTTP_HOST} ^rajiviyer\.in [NC]
RewriteRule ^(.*)$ http://www.rajiviyer.in/$1 [R=301,L]
# Redirect site root to main directory
RewriteRule ^$ /main/ [R=302,L]
Once you're happy, change 302 to 301 to make the redirect cached by browsers and search engines.

Related

Redirect all pages containing a particular part to home using htaccess

Recently my site got hacked, and tons of pages were generated. Most of them end with strings like ?_t=77, ?_t=97, and ?_t=56 etc. Basically, the ?_t= part is common in all of them.
How do I create a .htaccess rule to redirect all the links with ?_t= to home?
Some redirects I've already created:
<IfModule mod_rewrite.c>
RewriteEngine On
Redirect 301 /profile/1320172681 /u/DanLiu
Redirect 301 /profile/387899125 /u/LuckyMaheshwari
Redirect 301 /profile/15379797 /u/manishchopra
Redirect 301 /profile/335596945 /u/MatthewNord
Redirect 301 /profile/94097446 /u/abhimanyu
</IfModule>
Thanks
With your shown attempts/samples, please try following htaccess rules. Please make sure to clear your browser cache before testing your URLs.
<IfModule mod_rewrite.c>
##making your Rewrite engine ON here.
RewriteEngine On
##Rewriting urls with ending with ?_t=digits to home page here.
RewriteCond %{QUERY_STRING} ^_t=\d+/?$ [NC]
RewriteRule ^ / [R=301,L,QSD]
##Rewriting home page url to index.php here.
RewriteRule ^/?$ index.php [QSA,L]
###put your rest of htaccess Rules from here onwards.
Redirect 301 /profile/1320172681 /u/DanLiu
Redirect 301 /profile/387899125 /u/LuckyMaheshwari
Redirect 301 /profile/15379797 /u/manishchopra
Redirect 301 /profile/335596945 /u/MatthewNord
Redirect 301 /profile/94097446 /u/abhimanyu
</IfModule>

Redirect 301 files from subcategory to root

I moved my prestashop from subcategory(/shop) to root and now,
to fix the 404 Not Found Errors, I have to redirect all pages
from
"example.com/shop"
to
"example.com"
(for example from "example.com/shop/skirt" to "example.com/skirt"). What do I have to add to .htaccess? thank you so much.
If you want to redirect
"example.com/shop/product-A"
to
"example.com/product-A"
try with
RewriteEngine On
RewriteRule ^shop/(.*)$ /$1 [L]
If you want to redirect the browser so that the new URL appears in the location bar, add an R flag in square brackets:
RewriteEngine On
RewriteRule ^shop/(.*)$ /$1 [L,R=301]
You can use the following Redirect in your htaccess :
Redirect 301 /shop/ http://example.com/
This will 301 redirect your subfolder to the root including all pages and directories from /shop to / .

htaccess how to redirect all pages in the directory to index page

I want to redirect from all pages to index page in the directory.
And wrong addresses too.
http://site.com/directory/anyword move to http://site.com/directory/index.html
I did in .htaccess RedirectMatch 301 /directory /directory/index.html
But I need except directory/thankyou.html
It does redirect but doesn't open index.html - resulted in too many redirects
May be I can try with 404.
You need to exclude index.html from your match, otherwise you get an infinite loop where directory/index.html redirects to itself over and over.
Unfortunately my knowledge of writing .htaccess files is basically nonexistent so I can't provide an example.
Mod Rewrite?
RewriteEngine On
RewriteCond %{REQUEST_URI} !index\.html$
RewriteRule /directory/.+ /directory/index.html
You can redirect all pages or subdirectory to the index page.,
try this-
root/.htaccess
enter code here
DirectoryIndex index.php
RewriteEngine On
RewriteBase /
RewriteRule ^(.+?/)?home/?$ $1/index.php [L,NC]

htaccess URL rewrite rule for everything under a folder

I have looked but can't find anything that works. I have an old site that we have updated. They had everything under a folder called site under the root. Now all the customers who have this bookmarked I would like to redirect them, regardless of what is after the folder site (subfolders, files), to the main page of the new site instead of page not found on our new WordPress install. Any help appreciated.
Old URL: http://www.oldsite.com/site/.... to new URL http://www.newsite.com
I have tried this to no avail
Rewrite Rule ^site/(.*)$ http://www.newsite.com
Thanks.
try:
RewriteEngine On
RewriteCond %{HTTP_HOST} oldsite.com$ [NC]
RewriteRule ^site/(.*)$ http://www.newsite.com/$1 [R=301,L]
This redirects something like http://www.oldsite.com/site/some-page.html to http://www.newsite.com/some-page.html (the matching bit of the URI after /site/ gets carried over in the 301 redirect), but if you want to redirect everything for /site/ to the index root of newsite, replace the target in the RewriteRule to http://www.newsite.com/ (remove the $1 bit).
EDIT:
I actually write it wrong above. It is actually the same domain name. The question should read old URL mysite.com/site.... everything under this folder to just redirect to mysite.com
Then what you want is:
RewriteEngine On
RewriteRule ^site/(.*)$ /$1 [R=301,L]
Or alternatively with mod_alias:
RedirectMatch 301 ^/site/(.*)$ /$1
Looks like all you need is this simple 1 liner rule:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^site/ / [R=301,L,NC]

subdomain redirection using htaccess

I need to redirect the url http://testing.domain.com/ to http://testing.domain.com/admin/index.php
I think you are trying to secure your home page. Put this php code in your index.php.
header("Location: http://testing.domain.com/admin/index.php")
exit;
If you got everything in admin folder, then you can use this one
Options -Indexes
RewriteEngine on
RewriteCond $1 !^(admin)
RewriteRule ^(.*)$ admin/index.php [L]
Put the following into your .htaccess file
Redirect 301 http://testing.domain.com/ http://testing.domain.com/admin/index.php

Resources