Your current RewriteRule pattern is ^(.*)$ which captures the entire URI. The logs show it’s processing “/user/login” correctly (it’s being recognized). The RewriteConds look correct in syntax, but there might be a subtle issue.
The problem might be related to how the pattern matching is working. Let’s modify the rules to make them more explicit and add some debugging. Here’s a suggested fix:
# Add this line to enable detailed logging
RewriteEngine On
RewriteLog "/var/log/apache2/rewrite.log"
RewriteLogLevel 3
# Modified rules
RewriteCond %{REQUEST_URI} !^/user/login
RewriteCond %{REQUEST_URI} !^/contactus
RewriteRule ^(.*)$ https://newsite/$1 [R=301,L]
Note the use of ^ at the start of the path in RewriteCond patterns. Also, turned on detail logging, to help future debugging.
The log entry you shared actually indicates the rule is working as intended - when it says “pass through /user/login”, it means it’s NOT redirecting that URL, which is what you want.
To verify this is working correctly, you should test these scenarios:
My problem is following, I have an original site and a new site. The new site has a couple of links to old site with forms, and I want to keep the old site logic and the two pages, the first rewrite.
My conf file is:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin info@originalsite
ServerName originalsite
ServerAlias www.originalsite
DocumentRoot /home/au/drupal/docroot
AssignUserId au au
Protocols h2 http/1.1
RewriteEngine On
LogLevel alert rewrite:trace3
RewriteCond %{REQUEST_URI} !user/login
RewriteCond %{REQUEST_URI} !contactus
RewriteRule ^/(.*)?$ https://newsite$1 [R=301]
<Directory /home/au/drupal/docroot>
Options FollowSymLinks
AllowOverride All
Require all granted
RewriteBase /
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</Directory>
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/originalsite/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/originalsite/privkey.pem
</VirtualHost>
</IfModule>
The last line of the log:
[rid#7f1ed4a4a480/initial/redir#1] redirect to https://newsiteindex.php?destination=/investors/docs [REDIRECT/301], referer: https://www.newsite/
The second rewriteRule kills the intent of what I want to do as seen in the log file.
What would be a way to get it done?
Thanks.
I solved my problems.
I have a newsite.com and an originalsite.com.
I want a couple of links from the newsite.com to point to oldsite.com pages and to keep their functionality.
I thought using URL (/user/login, contactus) would work but it does not.
Part of the problem is server logic and there were more rewrites happening…
Using HTTP_REFERER did the trick.