Bluehost mod_rewrite not working (code attached) - .htaccess

I use Bluehost to host website for my client for two years, the website was running perfect before, until there's a billing issue that lead Bluehost to suspend my account. Anyway, the billing issue was solved and the server is back!
BUT, the website is down due to mod_rewrite is not working. I have contact Bluehost customer service staffs for 5 times, and their responses are the same “The .htaccess is enabled and this is a coding issue, you should contact your developer, we do not support for coding part.”
Even I explained that I am a developer and I am 100 percent for sure that is a server issue but still kicked out from the chat every time.
I have tested the code and I'm pretty sure it's correct. But I still need someone's help to let Bluehost staff know the code is correct.
There are only two files on server:
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^ index.php [L]
</IfModule>
index.php
hello
no matter what I request
- example.com/foo
- example.com/bar
The webpage should display a hello instead of 404 page.
Is the code above correct?

Related

Why doesn't this simple RewriteRule work anymore and why does google keep seeing it?

Some time ago (I think a couple of years) this simple RewriteRule in my htaccess stopped working.
RewriteRule tags/ tags.php [L]
It worked for years, then a day after a server change or a server upgrade or switch to php-fpm (I don't remember) it stopped working.
I solved it by deleting it, and sending all my links directly to the tags.php file.
This rule is part of a small CMS that I use for many of my sites. The sites work and everything works correctly.
But punctually when I create a new site, after a few days google sends me a warning telling me that the url mysite.com/tags/ creates an error 404.
And this is strange, because the url mysite.com/tags/ no longer exists for years now in my sites, nor in my sitemaps, I am sure because it is used only once in the main menu of my sites, and has been replaced with mysite.com/tags.php.
Above all it cannot exist in new sites. At first I didn't pay much attention to it on old sites. Probably google may have seen it in the old sites, and haven't forgotten it yet, but surely can't have seen it in the new sites.
So, I have a couple of unanswered questions.
The first and perhaps most important to understand: How does google see the url mysite.com/tags/? Is it possible that google reads my htaccess to understand what kind of url I'm going to create?
Second: how can I solve the problem permanently?
--------------------------update---------------------
Sorry for the delay with which I reply (summer vacation).
Regarding anubhava's answer, I have a doubt, but it's my fault, maybe I omitted part of the code.
The next rule says:
RewriteRule ^tags-([^/]+)\/$ tags.php?letter=$1 [L]
and makes work some urls like:
mysite.com/tags-k/
and these urls work, but if I put a 301 redirect on tags.php, will they still work?
No, Google (or any other) search bot cannot read your .htaccess
It is difficult to figure out how search bot found /tags URI but it is definitely hidden somewhere in your web pages.
Now to tell search bots that /tags doesn't exist is to use a redirect rule with R=301:
RewriteEngine On
RewriteRule ^tags(/.*)?$ /tags.php [L,NC,R=301]
With this 301 rule search bot will eventually let go old /tags/ result and will remember /tags.php only.

htaccess block and allow sites from the same domain name

I run a service where I offer css files and scripts and images for a third party website www.myfantasyleague.com that is a football hosting service for fantasy football and recently they have went through some changes over the last couple of years.
I am trying to block certain websites on their servers that are using my work fraudulently, while allowing the folks whom purchase my work on the same domain to be able to use my work and it not be blocked by the HTA file. Once you create a football site MFL gives it a permanent server number and 5-digit code that never changes now from each year it stays the same. Here is a link to a MFL search for the word football, and you can see there are many sites and if you click on a few they all have different 5 digit IDs and some have different server ID’s.
The site I want to start with to block, would be this site url below, and the MFL domain has an option to have http and https now, so getting both protocols would be idea.
SITE TO BLOCK EXAMPLE
https://www67.myfantasyleague.com/2019/home/63928#0
SITE TO ALLOW EXAMPLE
http://www51.myfantasyleague.com/2019/home/46087#0
On myfantasyleague domains they give each site its own 5-digit unique code at the end of the url, and also many are on different server id’s, like the www67 and the www51, and you see those 2 links one is https and one is http.
In the past I use to use this code below and it will still work today, however once I add it to my root access file, it takes out both sites and I can’t have that, as I want to be able to control which sites are blocked by the server number and the 5-digit league ID if possible.
CODE THAT I TRIED THAT WORKED BUT KILLS ALL SITES FROM THAT DOMAIN NAME.
RewriteEngine On
RewriteCond %{HTTP_REFERER} https?://(www\.)?www(67).myfantasyleague.com.+(63928) [NC,OR]
RewriteRule .*\.(jpe?g|gif|bmp|png|js|css)$ [L]
Maybe i can turn that URL to be blocked into the actual IP and try blocking the IP?
I don't know what else to try and it might not even be possible i dont know. I appreciate any and all feedback.
Thank you
Though the pattern you posted certainly can be improved there is no reason why it should "block" all referrers from that host, if those sites send a referrer header at all ... Keep in mind that such header is optional and can be modified easily, so anyone can work around limitations you implement based on that header.
Blocking an IP on the other hand means you block all services from that host which is not what you want, as I understand. The numerical addition to the "www" prefix indicates that the service operator uses sharding to balance request load, an old and outdated approach. You can expect that to change any time, either for individual sites or in general, so better not rely on it. You are only interested in the numerical ID at the end of the referring URL.
Your issue with that approach you posted however is the actual rewriting rule: it is syntactically invalid. So I would expect it to raise an internal error, thus blocking all requests. I would suggest something like this instead:
RewriteEngine On
RewriteCond %{HTTP_REFERER} !/63928$ [OR]
RewriteCond %{HTTP_REFERER} !/63927$ [OR]
RewriteCond %{HTTP_REFERER} !/63926$
RewriteRule ^ [F,NC]
This would actively white list specific sites by mentioning their numerical ID and block all other requests by sending out a "Forbidden" header.
Please note that I have not actually tested above code, it might contain some minor glitch which you might have to fix. For such things it is important to have access to the http servers error log file. Not sure if you have it in your situation...

my site hijacked, added url on my site and can't be redirected

My site hacked and they add url with string "bitsofev" for example:
http://example.com/~bitsofev
http://example.com/~bitsofev/apple.de
Check here for real sample
https://www.google.com/search?safe=off&q=bitsofev&nfpr=1&sa=X&ved=0CBsQvgUoAWoVChMI7LnMiOvIxwIVQpGOCh1T2wC6&biw=1570&bih=899
I tried to redirect it to homepage with htaccess but not working
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)~bitsofev(.*)$ http://example.com [L,R=301]
</IfModule>
I tried the same code to redirect other string and it works fine, but not "bitsofev" string. weird.
Best I can do for this is to block on robot.txt but its not solving the problem. What can I do for this?? Where can I fix the original problem? How to redirect it to homepage if I can't find the source?
Additional info: I searched on MySQL db, and I can't find 'bitsofev'.
I have a similar problem. Someone may have added the "/~bitsofev/apple.de" url to my site. A web analytics app track visitors and the content viewed at my site. Like you I don't have many users. Originally I thought that the "/~bitsofev/apple.de" was first accessed sometime last month. I originally also noticed that one of the user at my site registered at nearly the same time. My first thought was to temporarily deny this user access to signing into the site (and interacting with mysql db) while I investigated if this user uploaded a malicious file to the mysql db or exploited some error in the code that I was not aware of. However, I subsequently discovered (I hadn't been monitoring it regularly) a message from google regarding the url "~bitsofev/apple.de" in my admin inbox which predates the web analytics data and the user's registration that I originally thought may have been suspicious.
I will let you know everything further that I ascertain.
I meant to post this as a comment and not an answer. I apologize.
Add the the following to your .htaccess file:
RewriteCond %{THE_REQUEST} ~bitsofev/apple.de($|\ |\?) [NC]
RewriteRule .* - [F]
This will block (403 error) the file and url from being accessed. However, it wont specifically correct the problem.
I believe that was is really happening is that you are using shared hosting at Hostgator and IP 108.167.182.250 / 108.167.182.251
bitsofev (the owner of the site http://bitsofeverything.net/) is another user on the Hostgator shared hosting.
For example, go their website and after .net/ type in the tilde "~" symbol and the your user name (your hostgator user name), e.g, ~username
If I'm correct you'll then see your own website. You can then add a / and folders/files and see those, as well.
This is because Hostgator enables (by default) mod_userdir (Apache server).
The only part I don't understand yet is the apple.de because it doesn't appear to be a folder or file at bitsofeverything.net/
At any rate, I've been writing about this for a couple of months (trying to understand it better) at:
Justinbailey.info: What is /~bitsofev/apple.de added url? Hacked, hacker hacking.

htaccess redirect from development server

The server where I developed a wordpress site was indexed by google. The site is now live with the actual domain, but google searches find links to the site at development server adddress. The site is on the same server where developed, making it live was simply pointing the domain to this new site. I need to redirect these links, but am not having an luck.
Also, the developer server address has a tilda, which was indexed as %7E in google. I have tried various version of the following, all to no avail.
RewriteCond %{HTTP_HOST} ^cardgym\.dcaccess\.net
RewriteRule ^cardgym.dcaccess.net/~chrs/$ http://chrs.org/$1 [R=301,nc]
RewriteRule ^/%7Echrs/(.*)$ http://chrs.org/$1 [R=301,nc]
going to development server results in an 404 error in wordpress: http://cardgym.dcaccess.net/~chrs/
Thanks
Can you change your internal web server configuration so that the development domain is an alias of the live site? That would be the easiest solution imo.
Otherwise check out the answer by Sigg3.net here RewriteRule for tilde
If I understand you correctly your site is live and you moved it to the new domain.
So it appears you already have the live site up and going at http://chrs.org. So there is nothing you need to do to redirect it as far as Google indexing.
It will take Google time to crawl the new site and index it.
You can help speed up the process by asking Google to index your new site by submitting it here.
https://www.google.com/webmasters/tools/submit-url?pli=1
.htaccess does not control the way Google indexes the site. If its on the internet it will be indexed unless you prevent it. There are a few options you can do to help make those dev links disappear.
A. Add a robots.txt to the root of the dev site with this code below in it and that will keep Google/search engines that respect robots.txt from indexing it.
# Make changes for all web spiders
User-agent: *
Disallow: /
B. Block the site using htaccess protected directory for the whole site which will stop it from being crawled.
OR
C. Take the dev site down.
It appears you've already moved the dev site to live domain that's why you are getting 404. The links in Google will disappear eventually because they no longer exist. The next time Google tries to crawl your dev site and see's it's not there the links will be removed. The new site will start to show up as Google begins crawling it. There is nothing you can do right now but wait. It can literally take weeks.
If indeed you really are trying to redirect, then you can add an htaccess file on the cardgym.dcaccess.net site using redirect.
Redirect 301 /~chrs http://chrs.org

Mod rewrite only working on some computers

I've got a website where on the majority of computers it works absolutely fine, redirecting users to the correct pages using the .htaccess file.
However, some computers seem to be ignoring the rules in the .htaccess file (maybe even the .htaccess file completely).
RewriteEngine On
RewriteBase /
RewriteRule ^procyon$ /procyon.php [L]
When a user visits http://www.blackroc-technology.com/procyon it redirects them to a product page. However, for some users they get a 404 error.
Someone in the same building as me (same internet connection) is suffering from this problem - I've tried both IE and Chrome and neither work so it doesn't appear to be a browser issue.
There's also a handful of customers on other internet connections to ours which have reported the problem.
Any thoughts on this? It's seems very odd to me and hard to debug!
If you can reproduce both cases, working and not working, then do an client side HTTP capture, e.g. using Fiddler.
You can then diff the successful/unsuccessful request to try to narrow down the issue e.g. if bad requests always fail and good requests always succeed, when re-requested from Fiddler, regardless of which network, computer they are issued, then it is likely a server side issue (.htaccess or httpd.conf setting sensitive to one of the request attributes).
At the very least you will have a better idea of exactly what is transpiring vs just the end result of a 404.
You can also similarly enable logging on the server side (ideally in a staging enviroment, not production) e.g
RewriteLogLevel 9
to get more details on why bad requests result in a 404

Resources