Reputation: 25842
In order to redirect all requests from old domain https://old4.old3.old2.ua
to new domain https://new4.new3.new2.ua
I implemented the following rules in .htaccess:
RewriteEngine ON
RewriteRule ^(.*)$ https://new4.new3.new2.ua/$1 [R=301,L]
I also need to allow requests(with parameters) on old domain to the one following url
https://old4.old3.old2.ua/vacancies/rss
and do not redirect it to the new domain.
How to add this exception into the .htaccess rules?
UPDATED
I have the following .htaccess
file for my website:
RewriteEngine ON
RewriteCond %{REQUEST_URI} !/vacancies/rss [NC]
RewriteRule ^(.*)$ https://new4.new3.new2.ua/$1 [R=301,L]
Right now everything works as expected except one thing:
when I access following url: http://old4.old3.old2.ua/vacancies/rss?rid=34
it redirects me to http://old4.old3.old2.ua/vacancies/rss/?rid=34
with /
between rss
and ?rid
but the expected url in this case is the same url as originally requested - http://old4.old3.old2.ua/vacancies/rss?rid=34
My server configuration is the following - the website is running on Apache server behind Nginx proxy server.
This is Nginx config:
server {
listen 80;
server_name old4.old3.old2.ua;
charset utf-8;
gzip on;
client_max_body_size 100m;
client_body_buffer_size 128k;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
root /srv/www/htdocs/old4.old3.old2.ua/;
location / {
if (-f /srv/www/htdocs/old4.old3.old2.ua/maintenance.enable) {
return 503;
}
auth_basic "Restricted zone";
auth_basic_user_file /etc/nginx/bonus.passwd;
proxy_pass http://127.0.0.1:81;
proxy_redirect http://127.0.0.1:81 /;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
}
location ~^\/web\/images.*\.(jpg|jpeg|gif|png|ico) {
root /srv/www/htdocs/old4.old3.old2.ua/;
}
location ~* ^.+\.(htm|html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|bz2|pdf|odt|txt|tar|bmp|rtf|js|swf|svg|mp4|mp3|ogg|flv)$ {
root /srv/www/htdocs/old4.old3.old2.ua/web;
}
error_page 503 @maintenance;
location @maintenance {
rewrite ^(.*)$ /maintenance.html break;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /srv/www/htdocs/;
}
location ~ /\.ht {
deny all;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/certbot/live/old4.old3.old2.ua/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/certbot/live/old4.old3.old2.ua/privkey.pem; # managed by Certbot
include /etc/certbot/options-ssl-nginx.conf; # managed by Certbot
}
Apache config:
<VirtualHost *:81>
ServerName old4.old3.old2.ua
DocumentRoot /srv/www/htdocs/old4.old3.old2.ua
# if not specified, the global error log is used
ErrorLog /var/log/apache2/old4.old3.old2.ua-error_log
CustomLog /var/log/apache2/old4.old3.old2.ua-access_log combined
# don't loose time with IP address lookups
HostnameLookups Off
# needed for named virtual hosts
UseCanonicalName Off
# configures the footer on server-generated documents
ServerSignature On
Include /etc/apache2/conf.d/php7.conf
DirectoryIndex index.php
<Directory "/srv/www/htdocs/old4.old3.old2.ua">
Options Indexes FollowSymLinks
AllowOverride All
# Order allow,deny
# Allow from all
Require all granted
</Directory>
</VirtualHost>
What am I doing wrong and how to fix it?
Upvotes: 0
Views: 158
Reputation: 41219
You can use RewriteCond
directive to exclude the URI .
RewriteEngine ON
RewriteCond %{REQUEST_URI} !/vacancies/rss [NC]
RewriteRule ^(.*)$ https://new4.new3.new2.ua/$1 [R=301,L]
Upvotes: 1