helicon rule help for iis 7 - iis-7

We have links like this that users click on in emails.
https://www.samplesite.com/re/Jim.Smith
What is happening is they are getting redirected to the absolute url instead of the personalized url above.
So in the url after clicking on the link in the email it looks like this.
https://www.samplesite.com/sample_folder/landing.aspx?rid=Jim.Smith
We wish to keep the url link the same as the link in the email. The following is our helicon rule.
Can you tell me what if anything is wrong with this?
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_Host} (^(?:www\.)?www.samplesite.com$) [NC]
RewriteCond %{REQUEST_URI} !^/(robots\.txt|favicon\.ico)$ [NC]
RewriteRule ^/re/([^/]+)$ https://www.samplesite.com/sample_folder/landing.aspx?rid=$1 [NC,L,R]

You need a rewrite, instead of a redirect.
Change this:
[NC,L,R]
to this:
[NC,L,U]
The R is telling it to redirect, which is what you're experiencing. Removing the R will just do a rewrite.
(I like to include U which means to unmangle the url for the IIS logs, so the logs show the original url. This is up to you.)
As a side note, since your rule is checking for /re/... you don't need the line with the robots.txt and favicon.ico

Related

Redirect to home if url contains string with a dot using ,htaccess

My Wordpress site is under attack. A bot sends queries that crashes my MySql. All of them contains "/?s=" and ".pl" in the url, so, I whant to redirect to home if someone is trying to access them.
Example:
If www.example.com/?s=xxxxx.pl redirect to www.example.com/
If www.example.com/?s=123.pl redirect to www.example.com/
Can you help me? I couldn't find how to edit .htaccess to solve it.
You could use a more robust system like mod_qos to stop these types of attacks then it will automatically block them by IP and other ways.
However you can do something like this with rewrite rule and then it will get 403 forbidden.
RewriteEngine on
RewriteCond %{QUERY_STRING} s=(.+)\.pl
RewriteRule ^ - [F]
if you still want to redirect to home page you can do this.
RewriteEngine on
RewriteCond %{QUERY_STRING} s=(.+)\.pl
RewriteRule ^ /? [R=301,L]
Let me know how this works for you.

redirect a domain extension to a subdirectory

I am trying to create a permanent htaccess redirect (301) from all my domain extensions into the appropriate subdirectories. The "rules" are as follow:
Redirect belgian website to its subdirectory on the main website:
from: www.example.be
to: www.example.com/befr/
Of course I would like to preserve the url parameters (if any) of the "from". Globaly, if someone entered the first url it should redirect to the second url (langage subdirectory in the main website).
I'm using wordpress and I'm hosting on a plesk I've read many things here but I'm stuck, thank you very much in advance for your help
PS: I've tried that but it doesn't work
RewriteCond %{HTTP_HOST} ^(www\.)?example.be$ [NC]
RewriteRule ^(.*) http://www.example.com/befr/$1 [L,R]
After reading your question, your code should be working (with informations you gave).
If it's not, here are some points to check:
1. Make sure mod_rewrite is enabled and htaccess can be executed (Apache config).
2. Your htaccess has to be in root folder (where example.be is forwarded).
3. About your htaccess' code:
since you're using Wordpress, make sure your rule is on top of other rules
don't forget to escape . (second one) in RewriteCond (otherwise it doesn't mean the same) even if it works that way
replace R flag (302 by default) by R=301 if you want a 301 redirect
Your code now looks like this
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example\.be$ [NC]
RewriteRule ^(.*)$ http://www.example.com/befr/$1 [R=301,L]
# your other rules (and Wordpress' default rule) here

How to redirect with .htaccess wrong external urls containing an?

I have a wordpress website, and in the past I used a script that loaded in frame page the external urls using the folliwing string:
http://www.mywebsite.com/?out=http://www.externaldomain.com/...
but it was used by spammers for their purposes so I had to disable it, but now -in the world- every link like the one above show my hompage. I need to redirect all urls that have that structure to a custom 404 page, like if is ?out=http/... THEN redirect to 404 url page
Is it possible via .htaccess?
Thanks!
Try:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^out=([^&]+)
RewriteRule ^/?$ http://www.mywebsite.com/error.php? [L,R=301]

htaccess mod rewrite rule to over-ride cakephp controller

I have a site running cakephp and also a wordpress site together in the same root directory. I have the following issue. Wordpress is served requests first such that a url for the homepage will be routed through wordpress' index. Now our cakephp code includes a list of controllers that manage some special features of our site. We have a rewrite rule that looks as followed RewriteCond %{REQUEST_URI} !^/users. This allows urls like www.example_site.com/users to hit our cakephp framework instead of generating a 404 error when wordpress cannot find this page.
This rule bypasses the wordpress routing so that the request can be sent to cakephp. We are using a similar rule for each of our cakephp controllers. The issue is that we used to have a wordpress plugin that had a users page. This users page appended arguments to the url as followed www.example_site.com/users/some_dudes_username. Some links to these user pages are still indexed by google or in peoples bookmarks, so what is happening is the rewrite rule we wrote causes these to bypass wordpress (instead of 404ing there like it used to) and instead they hit cakephp and 404 there. I am thinking through how to make it so that any of our cakephp user controller functions are correctly redirected to (there are only a few so white-listing seems like the way to go), but any other request to the user controller for actions that will not exist like www.example_site.com/users/some_dudes_username would redirect to our FAQ page. I have the following white-list code which seems to work, but I cannot figure out how to correctly redirect everything else:
RewriteCond %{REQUEST_URI} !^/admin/users
RewriteCond %{REQUEST_URI} !^/users/login
RewriteCond %{REQUEST_URI} !^/users/admin_login
RewriteCond %{REQUEST_URI} !^/users/logout
RewriteCond %{REQUEST_URI} !^/users/admin_logout
RewriteCond %{REQUEST_URI} !^/users/admin_index
# Then I need a rewrite rule to take everyone else to the FAQ page.
Thank you to anyone that can help.
I am not sure I totally understand your issue, but it sounds like you need a RewriteRule like this:
RewriteRule ^/users/.*$ /URI/to/faq.html [R]
This rule should be right after your RewriteCond since the conditions only apply to the rule right after them.
Hope this helps.

Enable https using Rewrite Rule for specific URLs

I am new to Apache and I am finding it extremely difficult to understand the rewrite rule syntax.
Here is my setup:
I have a Wordpress MU site at mydomain.com
I have parked domains site1, site2.com that point to mydomain.com
What I want:
I want this URL http://mydomain.com/wp-login.php to redirect to the same address but with https first. I have seen several tutorials on how to do this but there is a problem.
My problem:
If I use something like
#RewriteCond %{HTTPS} !=on
#RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
this also redirects my other sites to https versions because they are parked domains and effectively loading the same htaccess code; since the certificate I have is only for mydomain.com I get certificate errors.
I need to only secure pages on the mydomain.com but only the wp-login.php page. Another issue is that this page can move around in the URL, IE:
mydomain.com/wp-login.php
mydomain.com/somecracp/wp-login.php
mydomain.com/wp-login.php?xys=5653
I need a regex which will detect the domain name of mydomain.com and the wp-login.php anywhere in the URL. I then need to force https for them. Can anyone build me the code please?
UPDATE:
I may have found part of the issue. It would seem that the login page itself is also trying to do some redirection. When I access the admin section of the site http://mysite.com/wp-admin it detects that you aren't logged in; it then redirects you to the login page but appends a redirect_to query string at the end like so:
http://mydomain.com/subdomain/wp-login.php?redirect_to=http%3A%2F%2Fmydomain.com%2Fsubdomain%2Fwp-admin%2F&reauth=1
It seems to do this so that once you log in successfully it can redirect you to the admin section you previously tried to access. This "redirect_to" and what comes after it is the URL it will redirect to once you log in.
I won't to go into details as to why but is there a way I can force it overwrite the above URL to go to mydomain.com/wp-login.php with none of the rediret_to crap?
Try this:
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain.com$ [NC]
RewriteCond %{HTTPS} !on
RewriteRule wp-login.php https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,QSA]
The regex part of the RewriteRule checks to see if there is any instance of wp-login.php in the request, and if there is, redirect to https.
Try
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} wp-login.php [NC]
RewriteRule https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
The rewriteCondition will check if https is off and request uri contains wp-login.php, then redirect.

Resources