I'm trying to deploy my own Dynamic DNS service at Dreamhost and following some guides managed to get the server side functioning perfectly - when I open a url the DNS A record for a subdomain gets updated.
But when I place the data on the router and try to make it work (following the standards at dyndns or no-ip) the router fails to update.
Here's what I have:
1. Server side works as I expected.
2. Router works when using the default services (tested with no-ip) to update IP.
3. If I fail the authentication on my server, then router throws an auth failed error - it's accessing the server and authenticating.
4. Tried logging to see if at any point the script is even accessed, and it's not.
So I think the router is requesting a url that is different than I expect. I tried with /, white /update/ and with /nic/update/
At this point I wanted to see what the router is actually requesting. Fired up XAMPP, installed Wireshark, and tried to set the router to update my own computer. Found the requests and found a 301 response since the router is asking for /nic/update? and I have it on /nic/update/?.
Browser handles this redirect transparently but the router seems to not be requesting the new url. Might need to mess with mod_rewrite?
As suspected, the router was taking the redirect as a bad reply.
After messing around with mod_rewrite I got it to work.
Used this:
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.cgi [L]
Related
I seem to have a problem whereby mod_rewrite is sending multiple requests back to my Lucee server. Sometimes 2 requests, sometimes 4 requests. I have a special application framework in Lucee to handle and manage all requests. It requires the request to be rewritten and proxied back to Lucee as "/" (root) with a request parameter set to the user requested URI. All of the rewriting appears to work properly but more than one request gets fired by the backend server. The following is my rewrite rule setup:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ "/" [E=vPath:$1,PT,NE,NS,L]
<If "-T reqenv('vPath')">
RequestHeader add "vPath" "%{vPath}e"
</If>
The RewriteRule simply grabs the URI and sets the environment variable "vPath", then rewrites the URI to "/" with the parameters:
PT (pass through to next handler)
NE (no URI escaping of output)
NS (not for internal sub-requests)
L (last rule)
This all seems to work just as needed, however, in testing I have verified that the request hitting the code behind in Lucee is actually getting called multiple times. If I turn RewriteEngine off, then only a single request is sent to the backend. Turn RewriteEngine on and multiple requests are again sent (anywhere from 2 to 6).
Also note that it doesn't seem to matter if I use "P" (force proxy) or "PT" (pass through to next handler), I get the same multiple request results.
Any help would be greatly appreciated. I am somewhat of a NUBE to mod_rewrite.
System:
OS: Linux 4.18.0-11-generic
Java: 1.8.0_181
Lucee: 5.2.9.31
Apache Tomcat: 8.5.33
Alex was correct in referring me to utilizing the logging for mod_rewrite. [hat tip to Alex, thanks!]
Take note that for mod_rewrite v2.4 and above, you simply use
LogLevel alert rewrite:trace6
And this will update the log file in
/var/log/apache2/error.log
My problem was that I was not accounting for other requests to files that don't actually exist that were also being redirected to the web root, like
/favicon.ico
The lesson here is to be certain to account for all requests being proxied back to the application server, otherwise it will simply execute the root request for each URI that is directed to the application.
I have a website (built in ruby with .erb extensions) with mixed content (like a Wistia video) and so want to have that URL as http://domain.com.
However, when users click on "register," I want to direct them to an EV SSL-encrypted https://subdomain.domain.com/register folder.
Both of the above URLs work just fine, and the https URL displays the green EV SSL properly.
BUT, if in the low-probability event a user were to type "http://*/register" into his browser's address bar, that goes to the same /register page and allows him to register on that non-encrypted page. I really do not want that to happen.
I want to redirect anyone who tries to access the /register file via http to only the EV SSL-encrypted one, that is: https://*/register
sorry for using * wildcard, but I can only post 2 links.
I'm using Ubuntu 12.04 OS on an apache2 server and generally modify via ssh on my Mac's Terminal app.
Put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^subdomain\. [NC]
RewriteRule ^register(/.*)?$ https://subdomain.domain.com/register$1 [L,NC,R=301]
Thanks for replying so quickly, Anu. That may have worked, but Rackspace support used a 301 redirect in a .conf file, and it definitely worked:
/etc/apache2/sites-enabled/domain.com.conf:5
==================================
redirect 301 /register https://subdomain.domain.com/register
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.
My question is regarding RewriteMap on apache2: I want to apply a rewrite condition, so that all request on my proxy are proxied to an completely new domain.
Eg localhost/test or any other url should just go to www.mydomain.com:
RewriteRule / http://www.mydomain.com [P]
Works fine. If I access localhost, I still see "localhost" in my browser address line, but mydomain.com is presented. BUT if I now click on any link on this mydomain site, I will get a "Not Found" response.
The sourecode of mydomain contains eg this link:
Link
If I access the site in a normal way, this would result in: www.mydomain.com/lab/sale.php, and works fine.
If I access the site through my proxy and the rewriteRule takes place, I would after the link click be directed to: localhost/lab/sale.php, which does not exist of course.
Question: how can I a user that accesses the site through my proxy browse on the whole site as if he would really access this site?
The RewriteRule directive isn't like a ProxyPass or Redirect where they essentially link 2 nodes together and everything following it also gets proxied. The rule that you have only proxies the request URI /, not /lab/ or /etc.php or anything else. You need to create a match and pass that along as a backreference:
RewriteRule ^/?(.*)$ http://www.mydomain.com/$1 [P]
Or you can use the %{REQUEST_URI} variable:
RewriteRule ^ http://www.mydomain.com%{REQUEST_URI} [P]
I'm trying to make an address redirect to another one without actually changing the URL in the browser address bar.
User go to /path/page.php and see what is displayed on /path/index.php.
In the address bar the URL remains /path/page.php.
This is the code for the redirection:
Options +FollowSymLinks
RewriteEngine On
RewriteRule page.php index.php [NC]
I'm wondering if I need to use [P] for this task :/
[P] is a proxy flag, you need it only for silent redirection to another domain or web-server (in this case Apache works like HTTP proxy). In your case page.php and index.php reside on the same server, so [P] flag is useless.