0

I have decided to introduce folders into my URLs for SEO reasons. Now im trying to 301 all the old URLs.

The physical location of these 100+ pages is in the root:

www.mydomain.com/pageA1.php
www.mydomain.com/pageA2.php
www.mydomain.com/pageB1.php
www.mydomain.com/pageB2.php

I now want the URLs to include a folder name - but the physical location to stay the same:

www.mydomain.com/a-waste/pageA1.php
www.mydomain.com/a-waste/pageA2.php
www.mydomain.com/b-waste/pageB1.php
www.mydomain.com/b-waste/pageB2.php

My current rules are:

RewriteRule a-waste/pageA1.php /pageA1.php
RewriteRule a-waste/pageA2.php /pageA2.php
RewriteRule b-waste/pageB1.php /pageB1.php
RewriteRule b-waste/pageB2.php /pageB2.php

This works fine in the sense that if I browse www.mydomain.com/a-waste/pageA1.php - this URL stays in my address bar and it shows the page physically located www.mydomain.com/pageA1.php.

Now if I add [R=301,L] to this rule to tell google its permanent, it no longer rewrites the URL, it just redirects it instead? What am i missing?

thanks. Alex.

Alfonzo
  • 25
  • 7
  • An internal rewrite, and an external redirect, are two different things. Trying to make the first one “permanent”, makes absolutely no sense to begin with. – CBroe Apr 28 '20 at 10:15
  • CBroe - does what im trying to achieve make sense? or am i completely off track? all URLs are 'internal' so your comment has only confused me more? – Alfonzo Apr 28 '20 at 10:19
  • You could do an external rewrite from the _old_ to the _new_ format, in addition to what you have now (which is the other direction, it rewrites the _new_ format, when requested, to the _old_ one which matches the existing files.) But for all the links you are in control of (i.e., within your own site), you should change what these links refer to directly in your HTML code - to not make such an external redirect necessary in the first place. – CBroe Apr 28 '20 at 10:25
  • What is 'external' vs 'internal' in relation to rewrites? is it 'external' when we change how it looks from the outside (ie to a browser)? so do I just wait for google to naturally drop my old URLs from their index? I thought I had to tell google (using a 301) otherwise i'd lose all my SEO ranking for the page? – Alfonzo Apr 28 '20 at 10:33
  • An external rewrite is the server responding with a `Location` header and a 3xx status code, upon which the client makes a completely new request. And internal rewrite just maps the URL the client requested to something else - in this case, to the physically exinsting script file. And yes, redirecting the old URLs, if they get still requested by someone, to the new ones, might be a good idea. But that you should change all your own links in the HTML you are creating, is a separate issue. That you kinda need to do anyway, for the whole thing to make sense to begin with. – CBroe Apr 28 '20 at 10:37
  • OK - ive made the changes recommended above and now all internal links have been updated to point to the new URLs - this is working fine. Only issue I have remaining now is that I have some inbound external links that still point to `www.mydomain.com/pageA1.php` and these still work - so how do I 301 these without my other .htaccess rules creating a redirect loop?. existing rule is: `RewriteRule a-waste/pageA1.php /pageA1.php` – Alfonzo May 04 '20 at 10:31
  • This is probably going to need something similar to https://stackoverflow.com/a/13225718/1427878 A RewriteCond that checks if the originall requested URL (`%{THE_REQUEST}`) was of the particular “old” format, and therefor needs to be externally redirected to the new one. – CBroe May 04 '20 at 10:38
  • thanks for your hep @CBroe - im still getting the Redirect loop error? My rules now look like this: `RewriteCond %{THE_REQUEST} !^test\ /[A-Z]{3,9}\.php RewriteRule /childtest.php /test/childtest.php [L,R=301] RewriteCond %{THE_REQUEST} ^test\ /[A-Z]{3,9}\.php RewriteRule test/childtest.php /childtest.php ` – Alfonzo May 04 '20 at 12:18

0 Answers0