0
votes

My site passes a variable (a phone number) in the URL between pages. It grabs the phone number from the database and writes the URL link as: url.com/phone-number/id.

However, if the target page does not have a phone number it is replaced with a 0, so, url.com/0/id.

In my .htaccess file to rewrite old query php parameters to clean urls I put a default url.com/0/id in the rewrite. Old pages did not have a phone number so all redirect will have the 0.

# 301 redirects ad
RewriteCond %{REQUEST_URI}  ^/page\.php$
RewriteCond %{QUERY_STRING} ^id=(\d+)$ [NC]
RewriteRule ^page.php$ /page/0/%1? [R=301,NE,NC,L]

My problem is Google is indexing all new pages with the url.com/0/id and not url.com/phone-number/id, even though if you browse the site you will see url.com/phone-number/id for pages with phone numbers.

I am not sure if it is my URL rewrite or Google bot's behavior that is causing this.

1

1 Answers

0
votes

Don't use R=301 for above rule as 301 means permanent redirect. Use 302 (temporary redirect):

RewriteCond %{QUERY_STRING} ^id=(\d+)$ [NC]
RewriteRule ^page\.php$ /page/0/%1? [R=302,NC,L]