What Should Go In A New htaccess File? - .htaccess

GoDaddy is suggesting that my website has malware. They suggest I review htaccess file...
The file doesn't seem to have much in it... but I guess my website needs it... ? (I'm a layman, by the way).
What should I do? Should I delete all code that is currently in the file? My website has just several pages.
Here is the code currently in the file:
RewriteEngine on
RewriteRule ^2693701498/(.)$ excitation-autographing.php [QSA,L]
RewriteEngine on
RewriteRule ^8460001373/(.)$ lucas-leia.php [QSA,L]
Not sure if that was placed there by whatever hacking bot attacked the website...
Thank you in advance!
Link to the website.

Related

Redirect rule in .htaccess to catch all URL's that are not in the .htaccess file

I have used Stackoverflow a lot to find answers to my questions, but this time I can not find an answer. Maybe it is because english is not my native language and therefore I can not find the right query to search.
I have created a .htaccess files for redirects from our current website to our new website on a new domain. The .htaccess file has 266 rules now and it works fine (I have tested several rules and the redirects work fine on a individual level).
Now my question: I would like to create an extra rule that catches all the remaining URL's that are not in the .htaccess file and redirect all of that URL's to the new homepage. These include pages that we will not create on the new domain because they are outdated or pages that we maybe forgot etc.
I have tried several rules like:
RewriteRule ^(.*)$ https://www.newdomain.com/ [L,R=301,NC]
But this redirects all URL's to the new homepage, so it ignores all other rules I have made in de .htaccess file. Even if I put the rule in the end of the file.
I hope you guys can help! tnx in advance!
Pike
this may be not help much, but the "L" Flag tells Apache not to process any more rules if this one is used.
try
RewriteRule ^(.*)$ https://www.newdomain.com/ [R=301,NC]
and more rewrite cheatsheets in here

How to use .htaccess redirect

Okay, so I here .htaccess redirect is a pretty big deal, but I dont know how to do it. Honestly I'm a n00b, so can someone tell me how this is even accomplished? So far I know you have to have a page called
example.com/example.html
and then you want it to look like this:
example.com/example/
My problem is, how do you do that?
That can be achieved by adding the following to your htaccess
RewriteEngine On
RewriteRule ^(.*).html$ /$1/ [R,L]
The above will change any page with a html extension to FILEANME/

Best practice redirect to 'under construction' page after taking down old website

I have been asked to take down a website, and as such have removed the files and placed a new index page with a 'under construction' message while the new site is being created. Old pages from the site still show up in google, but now resolve 403-Forbidden.
I want these to redirect to the under construction page. This will likely be in effect for a few weeks, at which point I will want to permanently redirect (301) those pages to cooresponding pages on the new site.
Is there an easy trick (.htaccess) to make this happen for me? Do I want a 303 redirect?
Any help would be greatly appreciated
EDIT
well thanks for the answers, I didn't realize until now that this is not an Apache server so htacess will not work. The code in the answers will definitely come in handy in the future however. I'm gonna poke around a bit to look for a solution and will ask another question if I'm stumped.
Try this, redirects to index.php;
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [NC,QSA,L]
</ifModule>
Put this in your .htaccess file, replacing index.php by the file it needs to redirect to.
RewriteEngine On
RewriteRule ^(.)+$ index.php [L]

Redirecting A Subdirectory and Cleaning the URL using .htaccess

So, this is somewhat of a strange situation. I'm hosting a development server for a person I'm working with in a subfolder of my website. Basically the file structure looks like this:
public_html/my_subfolder/public/index.php
So what I'm attempting to do is make it so that if a user types "www.mysite.com/my_subfolder" they are taken to the "public/index.php" page without the public subfolder appearing in the URL. It's kind of silly that I'm still messing with this, considering it's only a development server.
I'm just at the point where I've messed with it for so long I really want to get it to work now, so that, if nothing else, I'll learn something. Any help would be greatly appreciated!
Try this rule in your .htaccess file:
RewriteEngine on
Options +FollowSymlinks -MultiViews
RewriteCond %{REQUEST_URI} !^/my_subfolder/public [NC]
RewriteRule ^my_subfolder/(.*)$ /my_subfolder/public/$1 [L,NC]
This will redirect everything so make sure to serve your static files like js, css, images etc from my_subfolder/public as well.
try using the P flag
RewriteRule ^/foo(.*) http://bar$1 [P]
Thanks
S

Redirect dynamic subdomain to same subdomain with subpage. How?

I'm a little stuck in here. I need to get some help with this subdomain-situation.
I need to redirect http://dynamicsubdomain.example.com/ to
http://dynamicsubdomain.example.com/account/welcome.html.
How do I do this? I tried several things but all without result. The main problem is that I can't fetch the entered dynamic subdomain from the %{HTTP_POST} string from mod_rewrite.
Another issue would be that it's creating and endless loop. So it only needs to redirect on these conditions, not when there's a URL like http://dynamicsubdomain.example.com/test/page.html. Because else it will create and endless loop. It's just for the starting page from the website.
I hope y'all can help me out, it's one of the last but important things from my project.
Thanks in advance!
There are several options on the URL redirection wiki page. For example, how about dropping an index.php in the root that redirects to the destination?
header("Location: http://dynamicsubdomain.example.com/account/welcome.html");
Why does the domain matter so much if you are staying on the same domain, and just redirecting to a different path?
The UseCanonical setting in Apache may have an effect on this, but it is defaulted to on, which preserves the host and port specified in the request.
RewriteRule ^/$ /account/welcome.html [R,L]
Hey guys, thanks for your support/help but I found the solution myself. Quicker than I thought :)
This is what does the trick, I hope I can help someone with this:
RewriteCond %{REQUEST_URI} ^/$ [NC]
RewriteCond %{HTTP_HOST} ^([A-Za-z0-9]+).example\.com [NC]
RewriteRule ^ http://%1.example.com/account/welcome.html [L]
#gahooa: I need to do this because my mainpage example.com is just a sort of landing-page with no special things. The extra part of the URL "account/welcome.html" is for showing a page related to the "subdomains"-account (gahooa.example.com for example will show your profile page). In my app I catch up the subdomain by a preg_match so it knows witch account it has to load. I hope I'm clear :) But thanks anyway!
This is my first time i'm using Stackoverflow but it actually works great! Quick replies from experts, great work! I definitely will come back :)
If you really want to use HTTP_HOST:
RewriteRule ^$ http://%{HTTP_HOST}/account/welcome.html [L,R]
But like gahooa already said you don’t specify an absolute URL if you stay with the same host. The URL path will suffice:
RewriteRule ^$ /account/welcome.html [L,R]

Resources