Htaccess if HTTP_Host then send 403 - php

Exist a way in Htaccess to say If HTTP_HOST = my.subdomain.com Then block access (403) for the files .php and .html?
I want that the only files accessible throug my subdomain are Images.

Try:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^my\.subdomain\.com$ [NC]
RewriteRule ^(.*)\.(php|html)$ - [L,F]

Put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^my\.subdomain\.com$
RewriteRule \.(php|html)$ - [NC,F]

Related

How to redirect to another subdirectory with same name with .htaccess

I want to redirect my file in folder A to folder B with the same file name.
EG.
yourdomain.com/folderA/nosedigger.php
to
yourdomain.com/folderB/nosedigger.php
The .htaccess is at yourdomain.com/folderA/.htaccess.
I tried the following but it does not work like a charm. Need help. Totally have no clue what the codes in .htaccess really mean.
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/folderB/ [NC]
RewriteCond %{REQUEST_URI} ^/(.*)$
RewriteRule ^ /folderB/$2 [R=301,L]
To redirect from foldera to folderb, you can use the following redirect above your other rules
RedirectMatch ^/foldera/(.*)$ /folderb/$1
this should be all you need:
RewriteEngine On
RewriteRule /folderA/(.*) /folderB/$1 [R=302,NC]
maybe:
RewriteRule ^folderA(/.*)?$ folderB$1 [R=302,NC]

How can i redirect all subfolders to a single root folder

I am trying to redirect all calls to mysite.com/api/foo/bar/json?param1=1... to mysite.com/api
I've tried
RewriteEngine On
RewriteRule "^api/?(.*)" "/api" [R=302]
But it doesn't work because it redirects in a loop
You need to exclude the destination path you are redirecting to
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/api/?$
RewriteRule ^api/?(.*) /api [R=302]
First check file permission maybe you don't have to made edit on the .htaccess file. Then insert this line of code.
RewriteEngine on
RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]

How can we rewrite a url using htacess?

I want to change the url 'http://www.xxxx.com/en/index.php/publisher/dashboardadvtsr' to 'advertiser.xxxx.com/dashboard'.How to use htacess rewrite method for this?
RewriteEngine On
RewriteCond %{HTTP_HOST} ^xxxx.com/dashboard
RewriteRule ^(.*) http://www.xxxx.com/en/index.php/publisher/dashboardadvtsr
I tried this code in htacess, but it didn't work.Anybody please help me with a suitable solution.
You can use this rule as very first rule in root .htaccess of advertiser site:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^advertiser\.(xxxx\.com)$ [NC]
RewriteRule ^dashboard/?$ http://www.%1/en/index.php/publisher/dashboardadvtsr [L,NC,R=301]
I guess it's something like this instead...
RewriteEngine On
RewriteCond $1 ^dashboard$
RewriteRule ^(.*) http://www.example.com/en/index.php/publisher/dashboardadvtsr [L,R=301]
I'm not sure why you need to match HTTP_HOST if you're writing this in .htaccess file (which already resolves virtual host to the corresponding DocumentRoot folder)

htaccess redirect - subdomain with query ignored - subdomain only redirect to php

I want to allow sudomains containing queries or requests to be ignored:
e.g.
http://sub.domain.com/documents or http://sub.domain.com/index.php?user=fred
but if a URI is to a subdomain only
e.g.
http://sub.domain.com
if gets redirected to
http://sub.domain.com/portal.php
How do I do this using htaccess file ?
put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^/?$ /portal.php [L]

subdomain gives access to folder

I have created one sub-domain. It is also accessed via folder.
For example,
subdomain.website.com
which is also accessed in the following url
website.com/subdomain
How do i stop this? I think it can be done with htaccess. I am not sure.
In the htaccess file in website.com's document root, add these rules:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^subdomain.website.com$ [NC]
RewriteRule ^subdomain/?(.*)$ http://subdomain.website.com/$1 [L,R=301]
add following line in the .htaccess in your root directory:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^subdomain\.domain\.com$ [NC]
RewriteRule ^/(.*)$ http://subdomain.domain.com/$1 [L,R=301]

Categories