ISAPIREWRITE - Access to an external site without changing the url of my domain - isapi-rewrite

How to make a redirect from my website to an external website without losing my domain url using isapirewrite. For example my site has access to mydomain.com/IT esternaldomain.com, which upon entering the url link that should be mydomain.com/IT/Details

Actually the syntax may vary from the version (2 vs 3). Here's a generic example of a PROXY rule for ISAPI_Rewrite3:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP:Host} ^mydomain\.com$ [NC]
RewriteRule ^IT$ http://esternaldomain.com [NC,P,L]

Related

Create two different rules on .htaccess: redirect some urls to my old site and create 301 redirects for news from my old to new site

I'm trying to understand how to redirect some urls that on my new site are not yet active but redirect a few other to new imported page on my new website
Example
I have and joomla website i'd like to redirect
www.mywebsite.it/it to old.mywebsite.it/it
But have also some spercific 301 redirects for news and some page
it/notizie/2036-slugnews.html to notizie/year/notizia/slugnews
I'm working on Apache2, with mysql 5.7, php 7.2 and October Cms.
With mod_rewrite enabled and laravel
Read some examples on:
https://www.danielmorell.com/guides/htaccess-seo/redirects/introduction-to-redirects
Imagined i have to try to write a condition that get all urls after /it/*but insert an exception to write all except the ones with 301 redirects
Honestly can't figure out how to redirect write the condition.
Have you some suggestions?
You should place your special url redirects before general rule in your .htaccess file:
For example:
RewriteEngine on
RewriteRule ^it/notizie/2036\-slugnews\.html$ http://old.mywebsite.it/notizie/year/notizia/slugnews? [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.mywebsite\.it$
RewriteRule ^(.*)$ http://old.mywebsite.it/$1 [R=301,L]
If You new to redirects, I can suggest to use https://www.301-redirect.online/ 301 redirect generator for your special page to page rules. This generator is the best one I know at this moment.
Also, change http:// to https:// if your site uses secure connection.
after a series on trials i have found an intermediate solution:
RedirectMatch 301 ^/it(.*)$ https://www.mysite.it$1
RewriteRule ^it/genericpage.html https://www.mywebiste.it/genericapagetoredirect? [R=301,L]
RewriteRule ^it/notizie/2002-slug.html https://www.mywebiste.it/notizie/2019/notizia/slugtoberedirected? [R=301,L]
In this way i redirect my old https://www.mysite.it/it home page to https://www.mysite.it
and some urls with a one to one redirect
But is not my goal.
Reasoning on the subject i found the defnitive solution
My goal is to redirect
1) a bunch of url with a rewrite url 301
2) All the links which are not included in the list of rewrite url genrically to https://www.mysite.it
3) All bad link joomla website create from www.mysite.it/it/tags/* and www.mysite.it/it/components/* to www.mysite.it
In general the goal frankly is to mantain linked urls with high authority in the google search console.
Aware of this i tried to
RewriteRule ^it/genericpage\.html$ https://www.mywebiste.it/genericapage? [R=301,L]
RewriteCond %{HTTPS_HOST} ^www\.mysite\.it$
RewriteRule ^it/$ https://www.mysite.it/? [R=301,L]
and
RewriteRule ^it/genericpage\.html$ https://www.mywebiste.it/genericapage?[R=301,L]
RewriteCond %{HTTPS_HOST} ^www\.mysite\.it$
RewriteRule ^it(/.*) $1 [R=301,L]
But without success.
What do you think?

redirect subdomain to page unless other page is called

i am trying to redirect all subdomains with more than 2 letters :
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^([^\.]{2,})\.domain\.com$ [NC]
RewriteRule .* index.php?page=static&subject=%1 [L,QSA]
for example : about.domain.com to display content of domain.com/?page=static&subject=about
but the URL remains about.domain.com in the browser
as well as if you're on about.domain.com and requested another page on that domain ( all pages go through index.php?page=blablabla) you need to be redirected back to domain.com/(whatever requested)
Same-domain internal rewrites can be done with the [P] (proxy) option.
If you need to reverse proxy a URL from the same virtual host config, you might be able to get away with a [P] rule, but if the domain of the internal request is from a different virtual host (or on a different box entirely) you probably need to look at a ProxyPass config.
In either case you will need mod_proxy installed and enabled.

IsapiRewrite rules generate strange pages/folders?

i'm using IsapiRewrite from helicontech for my custom classic ASP shopping cart.
My actual httpd.ini file is:
[ISAPI_Rewrite]
RewriteBase /
RewriteCond %HTTPS off
RewriteCond Host: (?!^www.domain.com)(.+)
RewriteRule /(.*) http\://www.domain.com/$2 [I,RP]
RewriteRule /httpd(?:\.ini|\.parse\.errors).* / [I,O]
RewriteRule /(.+)-([^-]*)-([^-]*)-([^-]*)\.html$ /detail.asp?brand=$1&model=$2&id=$3&lg=$4 [L]
So i'm actually using this component only to rewrite the product detail page in a nice way.
Lately looking in google cache i find some folders with files inside cached by googleBot that doesn't exist on my server eg: domain.com/carrera-CHAMPION ... and so on.
The page drawn if i access these strange pages is the detail.asp page but without css and some js loaded.
I tested recently the site with Acunetix scanner and seems like he found too these strange folders.
First i added a javascript check to se if Jquery not loaded then that means the page is one of these so i throw an alert and redirect user to homepage ..
Do you know what could be ? or how i could solve this via a rule in httpd.ini?
Hope i make myself clear if no feel free to ask me details,
thank you
Can you confirm that when you disable ISAPI_Rewrite these strange pages/folders disappear?
Please note that ISAPI_Rewrite only rewrites response headers and can't generate anything, so it's highly unlikely to be the cause of the issue.
BTW, your config is the mixture of ISAPI_Rewrite 2 and 3 syntax. If it's v2, please fix it like this:
[ISAPI_Rewrite]
RewriteCond %HTTPS off
RewriteCond Host: (?!www.domain.com).+
RewriteRule /(.*) http\://www.domain.com/$1 [I,RP]
RewriteRule /httpd(?:\.ini|\.parse\.errors).* / [I,O]
RewriteRule /(.+)-([^-]*)-([^-]*)-([^-]*)\.html$ /detail.asp\?brand=$1&model=$2&id=$3&lg=$4 [L]

dynamic subdomains with htaccess: URL shouldnt change in the browser

Trying to implement subdomains with htaccess.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.
RewriteCond %{HTTP_HOST} ^([a-z0-9]+)\.domain.com(.*)$
RewriteRule ^(.*)$ http://domain.com/index.php?/public_site/main/%1/$1 [L]
</IfModule>
when i enter ahser.domain.com the browser URL is changing. is there a htaccess option to not let this happen when absolute URLs is used in RewriteRule?
Don't rewrite to a full URL with domain in it. That generates a redirect since it's going to a different website! You could put microsoft.com there; so how would it work without redirecting?
What you have to do is make sure that the web pages work under the original domain. So when the client asks for myname.domain.com/... how about rewriting that to myname.domain.com/index.php?public_site/main/myname/.... Keep the domain the same. The index.php? can be made to work in any of those domains. For instance, even this could work:
http://OTHER.domain.com/index.php?public_site/main/MYNAME/...
I.e. set it up so it doesn't matter which virtual host accesses that path.
Once you have that, the rewrite can then just do:
# will not trigger redirect
RewriteRule ^(.*)$ /index.php?/public_site/main/%1/$1 [L]
You have to be careful not to introduce a loop since you're now redirecting a URL to a longer URL which matches the same rewrite rulethe same domain. You need an additional RewriteCond not to apply this rewrite if the URL already starts with /index.php?public_site/.

Apache2 redirect all but some pages back to http using vhosts

I am using rewrite rules with Apache 2 to redirect certain types of pages to HTTPS using vhosts. These are anything that starts with mydomain.com/users. In other words, all pages having to do with users and their information should be on HTTPS. I want to redirect all other pages to HTTP.
What happens now is that when a user goes to a /users page, he is redirected fine to HTTPS. But when he navigates away from the /users area, I can't get the redirect back to HTTP.
I need the rules and conditions to rewrite anything that is NOT /users/* to HTTP. In other words, please help me fill in the blanks:
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{REQUEST_URI} __blank__
RewriteRule __blank__ http://mydomain.com%{REQUEST_URI} [R=301,L]
In researching this, there are a few things I am trying to avoid. I need a wildcard under /users because I am developing the app and often add pages under users (it's a Rails app).
I understand that it is not easy to do a NOT match with regular expressions. All I am trying to do here is have the bulk of the site run on HTTP except the /users/* pages on HTTPS.
Also, yes I have a valid cert and yes I have verified that the Apache2 rewrite mod works. I can get all URLs rewritten to HTTP no problem. How do I NOT rewrite ones that start with /users in the REQUEST_URI? I think I have actually tried about every answer on this site so far...
There quite a few answers for this sort of questions, -- you just need to search this site a bit. Yes, they do not answer your question 100% straight away (as everyone has slightly different requirements -- like different page name etc) but the whole approach is the same.
In any case -- here how it can be done:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
# don't do anything for images/css/js (leave protocol as is)
RewriteRule \.(gif|jpe?g|png|css|js)$ - [NC,L]
# force https for /users/*
RewriteCond %{HTTPS} =off
RewriteRule ^/users/ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# force http for all other URLs
RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} !^/users/
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# your other rewrite rules below
These rules need to be placed inside VirtualHost directive BEFORE any other rewrite rules (if such present). If placed elsewhere some small tweaking may be required.
They will
force HTTPS for all resources in /users/,
do nothing for images, css styles and JavaScript files (to be precise, for files with those extensions)
and will force HTTP for all other URLs
IMPORTANT NOTE: It is very likely that these rule will not work for you straight away. That is because modern browser do CACHE 301 redirects from your previous attempts. Therefore I recommend testing it on another browser and change 301 to 302 during testing (302 is not cached) .. or clear all browser caches (maybe even history) and restart browser.

Resources