0

I'm an extreme novice at Apache, but I am trying very hard and doing my best to learn. However I've run up against an issue and although I've searched extensively (spent the last 3+ hours trying different things to try to make it work, lol), I've still been unable to find anything that does exactly what I need. However, (I think) this should be extraordinarily simple question for someone more versed in this than I.

What I'm needing is a simply RewriteRule that will take a URL (https://sample.example.com/login.htm?page=%2F), and when visited, redirect/change it to "https://sample.example.com/login.htm?page=%2Fui2.htm). I've tried rewrite rules, redirects, conditions, etc....but nothing I do gets there perfectly. I feel like I'm really, really, really close but I can't quite cross that last step. Here's what I have in the virtual host file this site matches to:

<IfModule mod_ssl.c>

<VirtualHost *:443>

ServerName sample.example.com
ServerAdmin webmaster@localhost


SSLCertificateFile /etc/letsencrypt/live/sample.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/sample.example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf


RewriteEngine on
RewriteRule "^/login\.htm$" "/login.htm?page=%2Fui2.htm" [R,L]


ProxyRequests Off
ProxyPreserveHost On
<Location />
        ProxyPass http://192.168.x.x:38374/
        ProxyPassReverse http://192.168.x.x:38374/
</Location>

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined


</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

</IfModule>

(the internal IP and domain names above are obviously masked)

I know the input text for the rewrite is working with certainty, it's just the re-written part that's failing. Everything works, except that it redirects me to https://sample.example.com/login.htm?page=Fui2.htm (i.e. it removes the "%2" part). Therein lies my problem.

1
  • 1 more attempt. Keep it as it is and use B and NE flags also. [NE,B,R,L] Commented Dec 16, 2016 at 7:27

1 Answer 1

1

Try escaping the %2 part with \s

Sign up to request clarification or add additional context in comments.

23 Comments

I tried changing the "%2" to "\%2" which didn't work...Are you saying to try "\%\2"?
@ohlin5 try \%2 and remove the double quotes from both regex string and replacement string.
I've tried both the suggestions the other poster here suggested, looks like he keeps editing it :) Anyways the neither worked...Most recent one redirects to sample.example.com/login.htm?page=Fui2.htm
OK so great news is that fixes the URL...Bad news is it still doesn't load as I now get caught in a redirect loop (browser says site redirected too many times and throws error). Thoughts there?
I got it!!! "RewriteCond %{QUERY_STRING} ^page=%2F$" (right above the rewrite, without the double quotes) did the trick! Thanks so much for the awesome help man!!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.