I have a huge amount URLs that needed to redirect to a single page. on a Cpanel server, I am using this code in .htaccess for redirect anything after /my-links/ to /new-page.
RewriteRule ^/?old-links/.+ /new-page/ [R=301,L]
I want to do the same thin my other server that has Nginx as a Web Server and Reverse Proxy for Apache. I used the same code in .htaccess but the redirect not working.
In my Apache config I have enabled allowoverride all and my Nginx config like this
server_name domain.com www.domain.com;
root /home/username/public_html/;
index index.php index.htm index.html;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
proxy_pass http://ip:8080$request_uri;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location ~ /\. {
deny all;
}
I have converted .htaccess code to Nginx redirect code and it's working fine now.
rewrite ^/?old-links/.+ /new-links;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.