REQUEST_URI must NOT end on - mod-rewrite

how can I do this?
RewriteCond %{REQUEST_URI} !payment\.callback\.php$ [NC]
the uri must not end on payment.callback.php
EDIT:
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(secure)\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !payment\.[^.]\.php$ [NC]
RewriteRule ^(.*)$ https://%1.domain.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(demo|secure)\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/_domain\.com/_secure/ [NC]
RewriteRule ^(.*)$ /_domain.com/_secure/$1 [L]
I don't want to rewrite (http => https) urls to secure.domain.com that ends on payment\.[^.]+\.php$

Related

How to point a subdomain to a subfolder

I have an Apache server running ISPConfig. On a domain example.com I am pointing its subdomains to subfolders, e.g. foo.example.com to /sub/foo. This works fine:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/example\.com/
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^/(.*)$ /sub/%1/$1 [L]
Now I need to point one specific subdomain into a subfolder's subfolder (bar.example.com into /sub/bar/public to use Laravel). But for some reason, this does not work:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^bar\.example\.com/
RewriteRule ^/(.*)$ /sub/bar/public/$1 [L]
RewriteCond %{REQUEST_URI} !^/example\.com/
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^/(.*)$ /sub/%1/$1 [L]
The problem was the / at the end of the domain name. If I delete it or put there $, it works.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^bar\.example\.com$
RewriteRule ^/(.*)$ /sub/bar/public/$1 [L]
RewriteCond %{REQUEST_URI} !^/example\.com/
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^/(.*)$ /sub/%1/$1 [L]

laravel htaccess force www

I have this .htaccess from laravel 6
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# force www ???
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
and what I want is to force from non-www to www
I have tried several combinations but is not working (i get "redirected you too many times")
What I have tried
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s on(s)|offs()
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [NE,L,R]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
How to force www ???
Try Also
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.yourwebsite.com/$1 [L,R=301]
RewriteCond %{HTTP} off
RewriteRule ^(.*)$ http://www.yourwebsite.com/$1 [L,R=301]

Having difficulty OHS rewrite rule for multiple domains

I'm having a bit of difficulty with rewriting on Oracle HTTP Server for multiple domains that point to same IP address and port
Following is working
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ https://sub-doamin-1/psp/UACMP/SELF_SERVICE/SA/c/NUI_FRAMEWORK.PT_LANDINGPAGE.GBL [R,L]
However when I try https://sub-doamin-2/analytic it redirects to the https://sub-doamin-1/psp/UACMP/SELF_SERVICE/SA/c/NUI_FRAMEWORK.PT_LANDINGPAGE.GBL
Tried RewriteCond ${HTTP_HOST} method with no luck. It just redirect to / (root)
RewriteEngine On
RewriteCond ${HTTP_HOST} sub-doamin-1$ [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ https://sub-doamin-1/psp/UACMP/SELF_SERVICE/SA/c/NUI_FRAMEWORK.PT_LANDINGPAGE.GBL [R,L]
RewriteCond ${HTTP_HOST} sub-doamin-2$ [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ https://sub-doamin-2/analytics
Can you please assists resolving this issue?
It should be %{HTTP_HOST} instead of ${HTTP_HOST}
So the rules should be:
RewriteCond %{HTTP_HOST} sub1.test.com$ [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ https://sub1.test.com/psp/UACMP/SELF_SERVICE/SA/c/NUI_FRAMEWORK.PT_LANDINGPAGE.GBL [R,L]
RewriteCond %{HTTP_HOST} sub2.test.com$ [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ https://sub2.test.com/analytics [L]
You can check the rules here: https://htaccess.madewithlove.be?share=6632e45c-a7bb-5099-ab0b-468ba1066277
for the urls https://sub1.test.com and https://sub2.test.com
If you write your original rules in that website you will get This test string is not supported: ${HTTP_HOST} so this can also help you next time.

how to set language

how can I set the language (en, da, de etc) with mod_rewrite?
all files are located in the same dir
url to set language is
?set_lang=da
rewrite:
www.domain.com/en/index.php => www.domain.com/index.php?set_lang=en
www.domain.com/en/another_page.php?cat=black => www.domain.com/another_page.php?set_lang=en&cat=black
www.domain.com/da/index.php => www.domain.com/index.php?set_lang=da
www.domain.com/da/another_page.php?cat=black => www.domain.com/another_page.php?set_lang=da&cat=black
EDIT:
my .htaccess looks like this
RewriteCond %{HTTP_HOST} ^domain\.net$ [NC]
RewriteRule ^(.*)$ http://www.domain.net/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.domain\.net$ [NC]
RewriteCond %{REQUEST_URI} !^/_domain\.net/ [NC]
RewriteRule ^(.*)$ /_domain.net/$1 [L]
RewriteCond %{HTTP_HOST} ^(demo|mysql|secure)\.domain\.net$ [NC]
RewriteCond %{REQUEST_URI} !^/_domain\.net/_(demo|mysql|secure)/ [NC]
RewriteRule ^(.*)$ /_domain.net/_%1/$1 [L]
RewriteCond %{HTTP_HOST} domain\.net$ [NC]
RewriteCond %{REQUEST_URI} !^/_domain\.net/ [NC]
RewriteRule ^(.*)$ http://www.domain.net/$1 [L,R=301]
I found a solution
RewriteCond %{HTTP_HOST} domain\.net$ [NC]
RewriteCond %{REQUEST_URI} ^/(da|en)/(.*)(\?%{QUERY_STRING})?$ [NC]
RewriteRule ^(.*)$ /%2?%{QUERY_STRING}&set_lang=%1 [L]

.htaccess blocking images on some internal pages

I'm doing some web design for a friend and I noticed that everywhere else on her site images will load fine except for the subdirectory I'm working in. I looked in her .htaccess file and sure enough it is setup to deny people from stealing her images. Fair Enough, except the pages i'm working on are in her domain and yet I still get the 403 error. I'm pasting the .htaccess contents below but I replaced the domain names with xyz, 123 and abc.
So specifically the page I'm on (xyz.com/DesignGallery.asp) pulls images from (xyz.com/machform/data/form_1/files) and it results in a forbidden error.
RewriteEngine on
<Files 403.shtml>
order allow,deny
allow from all
</Files>
RewriteCond %{HTTP_REFERER} !^http://xyz.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://xyz.com/machform/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://xyz.com/machform/data/form_1/files/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://xyz.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://abc.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://abc.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://abc.xyz.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://abc.xyz.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://123.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://123.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://123.xyz.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://123.xyz.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.xyz.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.xyz.com/machform/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.xyz.com/machform/$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.xyz.com/machform/data/form_1/files/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.xyz.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.abc.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.abc.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.abc.xyz.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.abc.xyz.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.123.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.123.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.123.xyz.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.123.xyz.com$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]
deny from 69.49.149.17
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^vendors\.html$ "http\:\/\/www\.xyz\.com\/Design_Gallery_1\.htm" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^vendors\.asp$ "http\:\/\/www\.xyz\.com\/Design_Gallery_1\.htm" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^ArtGraphics\.html$ "http\:\/\/www\.xyz\.com\/Art_Gallery_1\.htm" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^ArtGraphics\.asp$ "http\:\/\/www\.xyz\.com\/Art_Gallery_1\.htm" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^Gear\.asp$ "http\:\/\/www\.xyz\.com\/Gear_Gallery_1\.htm" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^Gear\.html$ "http\:\/\/www\.xyz\.com\/Gear_Gallery_1\.htm" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^NewsletterSign\-Up\.html$ "http\:\/\/www\.xyz\.com\/Newsletter\.htm" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^NewsletterSign\-Up\.asp$ "http\:\/\/www\.xyz\.com\/Newsletter\.htm" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^KidzStuff\.html$ "http\:\/\/www\.xyz\.com\/KidzStuff1\.htm" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^KidzStuff\.asp$ "http\:\/\/www\.xyz\.com\/KidzStuff1\.htm" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^Vendors\.html$ "http\:\/\/www\.xyz\.com\/Design_Gallery_1\.htm" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^Vendors\.asp$ "http\:\/\/www\.xyz\.com\/Design_Gallery_1\.htm" [R=301,L]
I'll bet its a syntax error in one of the directives, that you may have corrected when substituting www.xyz.com.
If you have access to httpd.conf, you could set up the RewriteLog and RewriteLogLevel directives to get a sense of what's going on when you try to load the images. You should be able to identify the offending line pretty easily. (Be sure to remove those directives once you're done.)
If you don't have access to httpd.conf, you can eliminate the lines one by one until you find the offender.
(Once that's all done, you could probably simplify that .htaccess file quite a bit. Most of those rewrite conditions are redundant. Easy for tiny errors to sneak in and not get noticed)

Resources