subdomain redirection using htaccess - .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

Related

How can I redirect everything in one sub directory using htaccess

I have a website and need everything in my subdomain to redirect to my home page.
For example I would need www.website.com/sub to redirect back to www.website.com
same with anything else within /sub
so www.website.com/sub/sdjdj/sdsd/dsd ....would also need to redirect to www.website.com
How can I achieve this with htaccess?
You can use:
RewriteEngine on
RewriteRule ^sub(?:/|$) / [NC,R,L]
You can use this in your .htaccess in the root.
RewriteEngine On
RewriteRule ^sub(?:$|/.*) / [R=302,L]
When you are sure the rule is working as intended, change to 301 in rule.

How to redirect directory to non-directory

I would like to redirect all links from www.gambitchessacademy.com/blog/url to www.gambitchessacademy.com/url
For example I want www.gambitchessacademy.com/blog/some-thing to redirect to www.gambitchessacademy.com/some-thing
How can I do this with htaccess? I'm using Joomla and the pages can be accessed by both /blog and non-blog. Thanks very much.
Put this rule as first rule in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteRule ^blog(/.*|)$ /$1 [L,R=301]

How to Permanent Redirect a Directory That No Longer Exists (via .htaccess)

I am having trouble redirecting an entire directory that no longer exists on our server.
All variations of the following are not working and I simply get a 404 Page Not Found.
.htaccess file looks like this:
redirect 301 /non_existent_directory/ http://my.website.com/existent_directory/
Is it possible to use the Redirect 301 directive for this? Or is this only solvable by mod_rewrite?
Thanks
I even tried:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?my\.website\.com\/non_existent_directory\/$ [NC]
RewriteRule ^(.*)$ http://my.website.com/existent_directory/ [R=301,L]
No luck...
From the Redirect documentation, I would say
Redirect 301 /non_existent_directory http://my.website.com/existent_directory
or
Redirect 301 /non_existent_directory /existent_directory
should work, provided you are allowed to use this in a .htaccess file. See also Troubleshooting .htaccess files. You should test without 301 though, to prevent caching of bad redirects by the client.
If this doesn't work, you can try a RewriteRule of course
RewriteEngine On
RewriteRule ^/?non_existent_directory(.*)$ /existent_directory$1 [R,L]
But this is equivalent to the above Redirect directive.

Redirect a request to different URL even if file exists

Ok so I need to redirect all requests to javascript files to a compression system I have created.
so admin/js/_global.js would redirect to _lib/compress.php?file=admin/js/_global.js
I have tried the follow htaccess code located in the root of the site but it just doesn't work.
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^admin/js/(.*)\.js$ _lib/compress\.php?f=admin/js/$1\.js [R=301,L]
Anyone have any ideas?
Try this : (don't forget to clear your browser cache)
RewriteEngine on
RewriteBase /
RewriteRule ^(admin/js/.*\.js)$ _lib/compress.php?file=$1 [L,R=301]
Try:
RedirectMatch 301 ^admin/js/.*$ _lib/compress\.php?f=admin/js/$1\.js

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]

Resources