Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess: How to permanently redirect a dynamic address, with no-follow, do-not-index directive using .htaccess

I have the following problem. The link format below no longer exist:

photos.domain.com/web/poppic.php?n=[any number from 0 to the roof]
Ej,: photos.domain.com/web/poppic.php?n=30

I replaced it, a year ago, to just: photos.domain.com/

Years after, I am still having tons of 404 errors. I need a permanent redirect, and an htaccess difective for search engines to do not follow and to no longer index that old link.

I tried rewriterule ^web\/poppic\.php?n=30 "http\:\/\/photos\.domain\.com" [R=301,L] will work. HOWEVER, I requires to write each line, from 0 to 9999999999999999999999999: rewriterule ^web\/poppic\.php?n=0 "http\:\/\/photos\.domain\.com" [R=301,L] rewriterule ^web\/poppic\.php?n=1 "http\:\/\/photos\.domain\.com" [R=301,L] rewriterule ^web\/poppic\.php?n=2 "http\:\/\/photos\.domain\.com" [R=301,L] etc.

How can I do it with a variable, to replace php?n=[number] for php?n=$variable (Or something like that)?

Also, it is not telling crawlers to do not follow/index the page.

Could you please help?

like image 763
Omar Avatar asked Dec 29 '25 17:12

Omar


1 Answers

You can't match against the query string inside of a rewrite rule using apache's mod_rewrite. You need to use a rewrite condition and match against the %{QUERY_STRING} variable:

RewriteCond %{QUERY_STRING} ^n=[0-9]+
RewriteRule ^web/poppic\.php$ /? [L,R=301]

Not sure how your original rule:

rewriterule ^web\/poppic\.php?n=30 "http\:\/\/photos\.domain\.com" [R=301,L]

ever worked. It doesn't work for me under apache 2.2 or 2.4.

like image 110
Jon Lin Avatar answered Jan 01 '26 12:01

Jon Lin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!