Redirecting all Unregistered Subdomains to Catch-All - apache

We'd like to redirect all misspelled subdomains to a catch-all (primary domain), ex. dalls.domain.com needs to resolve to domain.com. Due to the very large number of subdomains we have, we can't simply create redirects for each possible spelling. Is there a way to wildcard redirect all non-registered subdomains to domain.com?
Thanks for any help or insight!

Not sure if this is exactly what you are looking for, but you can redirect all 404's quite easily with htaccess. The only downside is that all mispelled(or non-existent) directories and files will also redirect.
You can do this by adding this to your .htaccess:
ErrorDocument 404 http://domain.com
Hope this helps! I will edit this answer if I find a specific redirect for just wrong sub-domains.

Related

Apache redirection to another port

I'm in trouble with understanding the apache configuration to redirect an http to another.
I need to redirect the following:
http://test.com/foo to http://test.com:34567
and
http://test.com/bar to http://test.com:33490
I have seen that with that lines it redirects to another address, but I need to know if it will work before doing anything.
Redirect permanent "/foo" "http://test.com:34567"
Redirect permanent "/bar" "http://test.com:33490"
Thank you!
Yes, it works, If anyone wants, I tried it in https://htaccess.madewithlove.be/

htaccess affecting addon domain

I have hosted a few sites on a Hostgator server. I have an htaccess for the main domain, limiting the access from a certain set of IPs. the main domain is in the root folder.
I have another website in a sub-folder which is being affected by the main htaccess file for ip block. I want that the ip block only goes for the main domain and none of the addon domains.
Please advice. I have read a lot of similar threads but the solution mentioned hasn't worked. The solution I found was adding the following code to the root htaccess file -
RewriteCond %{HTTP_HOST} ^(www.)?addon_domain.com
Rewriterule .* - [L]
I did replace the addon_domain with the actual domain with the correct TLD. When I add this, I get a 500 error.
It may have been the simplest of solution but for some reason, I couldn't find the answer online. One of my friends suggested to just use allow from all in the htaccess of the addon domain and it now works. :)

Strange behavior for missing files with short URLs

My webserver shows an error for missing pages. These URLs all 404:
http://my.web.site/missing.html
http://my.web.site/missing/
http://my.web.site/missing
But these URLs redirect to / with a 301 Moved Permanentlystatus code:
http://my.web.site/m/
http://my.web.site/m
Why do these URLs not 404? And how can I turn the 301 redirection off?
Since I don't have access to http.conf on this shared server (Apache), I am looking for a solution in .htaccess.
Just to clarify: What I want is that all missing pages 404.
Note:
The observed behavior (301 for one letter URLs) is the default on my (shared) webspace. There is no .htaccess file at this moment. I'm looking to resolve this issue with a .htaccess file.
The behavior described in my question is caused by the Apache module mod_spelling. Creating a .htaccess with
CheckSpelling Off
solved the problem.
I am disappointed that my bounty was awarded to an "answer" that (a) did not answer my question, (b) suggested a "solution" that would cause the exact behavior I was trying to avoid (301), and (c) my comment that points this out was ignored by the answerer.
as you know you don't have access of http.conf file so first you need to check that your htaccess rewrite is working or not
If it is working (for checking it you can write some environment variable
SetEnv APPLICATION_ENV dev_dev
and check in $_SERVER
Now time to do something in htaccess for 301 redirection
I have write this code in my HTACCESS
RewriteEngine on
RewriteRule ^testurl/?$ /home/? [L,NC,R=301]
I don't know you want to redirect from which URL to which , But
in my code xyz.com/testurl will redirect to xyz.com/home
here my application is codeIgniter so might be you have page extension .php or .html like this

Apache - redirect only the domain URL to a subpage

I have a shared hosting Apache server, and I'm trying to send visitors who come to the main domain URL to a specific page, with the URL replaced and a 303 redirect:
example.com
example.com/
to
example.com/subdirectory/page.html
Only the plain domain URL should get redirected, not:
example.com/page.html
example.com/otherdirectory
example.com/otherdirectory/
example.com/subdirectory
example.com/subdirectory/
example.com/subdirectory/otherpage.html
example.com/subdirectory/otherdirectory
example.com/subdirectory/otherdirectory/
example.com/subdirectory/otherdirectory/page.html
I'm not sure that RewriteEngine is allowed on this server, if there are alternative approaches possible.
The crude way I've thought of is to just use DirectoryIndex to send the visitor to example.com/index.php -- and have a PHP redirect in that file go where I want. But I'm not sure if this might produce a visible blip for some visitors, or how Google would feel about it.
I've found other instances of this kind of question on Stack Overflow, but the answers are failing for me in some way or another. As the behavior is not intuitive, testing before posting might be advisable.
Thanks
If mod_rewrite is not enabled you can use mod_alias based rule like this in your DocumentRoot/.htaccess:
RedirectMatch 303 ^/?$ /subdirectory/page.html
UPDATE: Equivalent mod_rewrite rule:
RewriteEngine On
RewriteRule ^/?$ /subdirectory/page.html [L,R=303]

redirect with htaccess

i need to redirect temporally a domain to a subdomain, this is my code for .htaccess:
Redirect 302 / http://m.domain.com/
this works great, but i have some subdirectories like: http://domain.com/photos, the code above redirects this way: http://m.domain.com/photos
i have a lot of subdirs and sub-subdirs, how i can redirect successfully all the subdirs to the same subdomain? (http://m.domain.com/)
Check out this post, I think it might help you. It looks like all you'd need to do is change your redirect to look something like:
Redirect 302 ^/.+/.*$ http://m.domain.com/
.htaccess redirect loop! All subdirectories to root
Hey, this is a tool for generating the redirect code, and lets you choose how the final URL looks, without knowing regex. Might help you.