Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I was wondering if the following scenario is possible using htaccess rules.
I want one subdomain to be redirected to another url.
I have contact the server admin to add the "test" subdomain to "example.com" domain.
The main domain has no other subdomains.
What rule must i put in htaccess to do achieve:
http://test.example.com to be redirected to http://www.something-else.com.
NOTE: www.something-else.com is a complicated url (200 chars length)
EDIT
My full htaccess file now looks like:
Options +FollowSymLinks
RewriteEngine on
RewriteOptions inherit
RewriteBase /
RewriteCond %{HTTP_HOST} ^test.example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/redir.php [L]
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
The htaccess file is located to example.com root directory.
I have no physical access to test subdirectory, although i know it exists - ping to that url shows me the IP of example.com
Typing test.example.com to the browser's address bar has no effect. White screen, no redirection, no nothing. If some page exists there, i know not.
For static urls:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^test.example.com$ [NC]
RewriteRule ^(.*)$ https://www.somdomain.com/a/folder1/somepage?var=xxx&var2=xxx&var3=xxx&var4=http://another-domain.com/folder1/xxxxx/?&var5=xxx&var6=xxxx [R=301,NC,L]
For Dynamic urls (if the original domain has folders that needs to be moved to the other domain):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^test.example.com$ [NC]
RewriteRule ^(.*)$ https://www.somdomain.com%{REQUEST_URI} [R=301,NC,L,QSA]
From your edit:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^test.example.com$ [NC]
RewriteRule ^(.*)$ redir.php [R=301,NC,L]
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have my website name as www.example.com but the 'example' is not related to any of my keywords.
But my competitors have. Is there any solution for index page?
All others Page maintains the proper naming_standard but for index page it creates a problem.
Here's my .htaccess code
RewriteCond %{HTTP:Host} ^example\.com$
RewriteRule (.*) http\://www.example.com$1 [NC,R=301,U]
RewriteRule ^/index.cfm$ http\://www.example.com [NC,R=301,U]
RewriteRule ^/main.cfm$ http\://www.example.com [NC,R=301,U]
RewriteRule ^/ww.example.com$ http\://www.example.com [R=301,L]
RewriteCond %{HTTP:Host} ^ww.example\.com$
RewriteRule (.*) http\://www.example.com$1 [NC,R=301,U]
Try this instead:
RewriteRule ^/index.cfm / [NC,R=301,L]
RewriteRule ^/main.cfm / [NC,R=301,L]
RewriteCond %{HTTP_HOST} !^www.example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
The first two rules stop people going to index.cfm and main.cfm directly and redirects them to the base URL.
The third condition and fourth rule check the domain is "www.example.com" and if it is anything else, e.g. without the www. or an alias, 301 redirects them to the same page on "www.example.com".
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I have setup my GoDaddy Shared Hosting account that no scripts should be run directly from server root - scripts start at least one subdir down. I also have subdomains which also fall in this category because it seems that my server simply rewrites the subdomains to selected folders.
/root
wordpress
drupal
app1
subdomains
sub1
sub2
sub3
I decided that I want www.mydomain.com to launch wordpress - so after quite a bit of research on SO and testing some solutions - this is the htaccess that worked. Other solutions were causing a 500 server internal error which I assume is a limitation of my hosting plan.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.mydomain.com$ [NC,OR]
RewriteCond %{REQUEST_URI} !wordpress/
RewriteRule ^(.*)$ wordpress/$1 [L]
</IfModule>
But now subdomains no longer work and from the server error message The requested URL /wordpress/subdomains/sub1/ was not found on this server. it is evident that my rewrite rules are kicking in for the subdomains.
I tried adding a RewriteCond %{REQUEST_URI} !subdomains befor the RewriteRule but didn't help.
Also RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d-all rewrites stop working.
How can I modify the rules so that specific directories/patterns should not be redirected? Or maybe if directory exists it shouldn't rewrite?
Try adding this before the rules that you have for wordpress:
RewriteRule ^subdomains - [L]
It should simply let requests that start with /subdomains pass through without doing any rewriting.
Replace your Rewrite rule with this:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ wordpress/$1 [L]
This will make sure wordpress/ redirection is not done for any file or directory.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
How can I block users from viewing sites that are located in the folder of main domain? For example: main domain is www.maindomain.com. When I create subdomain for another account in cPanel, it creates folder it it is accesible if someone type for example www.maindomain.com/subdomain. I would like to block certain folders, but leave others, as I have pages in folder: wwwmaindomain/contact-us. How can I do that? Hope it's clear enough :)
Try following RewriteRule in your .htaccess
RewriteEngine On
RewriteRule ^subdomain/(.*) /index.php [R=403,NC,L]
This will redirect any /subdomain request to your index.php with forbidden response code
Add these rules in the htaccess file in your document root (for maindomain.com):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?maindomain.com$ [NC]
RewriteRule ^(subdomain1|subdomain2|subdomain3) - [L,F]
This will return a "403 Forbidden" if you try to access /subdomain1, /subdomain2, or /subdomain3 from the maindomain.com host. If you don't want to return a 403, you can also redirect:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?maindomain.com$ [NC]
RewriteRule ^(subdomain1|subdomain2|subdomain3) / [L,R=301]
This redirects any access to the subdomains from the maindomain.com host to the document root.
Rules to add to the top of htaccess files found in the subdomain folders:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?maindomain.com$ [NC]
RewriteRule ^ - [L,F]
or
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?maindomain.com$ [NC]
RewriteRule ^ / [L,R=301]
very efficient way to do this is to place an blank index.php file the folders you do not want to show, so no need to mess with htaccess, or you can just create a new .htaccess with this code
deny from all
save this as .htaccess of that perticular folder you do not want to show to pubblic, however i perfer the first option.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I have a .htaccess that looks like this
RewriteEngine On
RewriteCond %{REQUEST_URI} !static/(.*)\.
RewriteRule ^(.*)$ index.php?controller=$1 [QSA]
It works fine. /static folder request remain intact, while others execute index.php file.
But now I have to add another rule. When a user navigates to /action/something, then /actions/something.php should be executed. But when I add the following line
RewriteRule ^action/(.*)$ actions/$1.php [QSA]
it breaks requests to static folder.
There is no reason, why it should break static, unless you wrote the new rule right after RewriteCond. What you should do however, rewrite to an absolute URL
RewriteEngine On
RewriteCond %{REQUEST_URI} !static/(.*)\.
RewriteRule ^(.*)$ /index.php?controller=$1 [QSA]
RewriteRule ^action/(.*)$ /actions/$1.php
The RewriteCond looks unusual. Unless there is a reason to rewrite static pages without a dot ., you should reduce the RewriteCond to just
RewriteCond %{REQUEST_URI} !static/
Update:
To prevent the infinite rewrites, you must add another exclusion condition
RewriteCond %{REQUEST_URI} !^/index\.php$
and action must be excluded as well
RewriteCond %{REQUEST_URI} !/actions?/
All put together gives
RewriteEngine On
RewriteCond %{REQUEST_URI} !/static/
RewriteCond %{REQUEST_URI} !/actions?/
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteRule ^(.*)$ /index.php?controller=$1 [QSA]
RewriteRule ^action/(.*)$ /actions/$1.php
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
The sub-directory is /addon/ it stores all data for my sub-domains a.k.a addon domains.
In this sub-directory I also store my primary domains data, my primary domain is website.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?website.com$ [NC]
RewriteCond %{REQUEST_URI} ^/addon/(.*)$
RewriteRule ^(.*)$ - [L,R=404]
Okay so that part is done, if I enter website.com/addon/mysecondwebsite-com I get a 404.
If I enter mysecondwebsite.com I see the contents of website.com/addon/mysecondwebsite-com.
This is great, thats what I wanted.
Now the tricky part, I already set up website.com to use website.com/addon/website-com. No need to tell me how to configure /addon/website-com for website.com. I need to disable 404 for website.com which is configured to use /addon/website-com/ but I also need to make sure if I enter website.com/addon/website-com that this directory is returned a 404.*
My rewrite conditions mention if I enter /addon/* on my primary domain (website.com) I will be returned a 404 error. This is great for my addon domains because they use /addon/ and not my primary domain. But how do I also block /addon/* but still use my primary domain?
website.com = 404 / BAD (website.com/addon/website-com)
mysecondwebsite.com = 200 / Good (website.com/addon/mysecondwebsite-com)
website.com/addon/mysecondwebsite-com = 404 / Good
website.com/addon/website-com = 404 / Good
Just so you get the full picture this is my .htaccess file for /public_html/
# Part one block direct access to /addon/ folder
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?website.com$ [NC]
RewriteCond %{REQUEST_URI} ^/addon/(.*)$
RewriteRule ^(.*)$ - [L,R=404]
# Part two using /addon/website-com/ as website.com directory
RewriteCond %{HTTP_HOST} ^(www.)?website.com$
RewriteCond %{REQUEST_URI} !^/addon/website-com/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /addon/website-com/$1
RewriteCond %{HTTP_HOST} ^(www.)?website.com$
RewriteRule ^(/)?$ addon/website-com/index.php [L]
Replace your 404 handler with this:
ErrorDocument 404 /404.shtml
RewriteCond %{HTTP_HOST} ^(www\.)?website\.com$ [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+addon/ [NC]
RewriteRule (?!^404\.shtml$)^.*$ - [L,R=404,NC]