Hello, Everyone!!!
I am hoping that someone can help me here!
I have a very old site that is being run on godaddy where I had to use the “?” in the “index.php?”,and I’m making the first real changes to it in something like eight years. I am updating this site, moving to another host, but I want to modify the .htaccess file to keep my links forwarding to the correct place.
Ideally, I would like to use a 301 redirect to change, but I realize now that a redirect can’t remove the “?”. So, I need to rework the rewrite rules and conditions, and I need help!
Just to spell out what I’m trying to do, here is the original link:
http://www.mysite.com/index.php?/old-template-group/old-page-template/this_is_the_article
…and I’m trying to get that to automatically redirect to:
http://mysite.com/new-template-group/new-page-template/this_is_the_article
I can successfully remove the index.php, the www., and change the old segments 1 and 2 to the new ones via the following:
I’m using this cut and pasted straight out of the EE3 documentation for removing the “index.php”:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/coast/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
…and it definitely successfully removes the “index.php” without any issues.
…and, worthy of mention, I’m using a generic rewrite to remove the “www.”, which also seems to be working fine:
# For removing "www.". Should be generic, so I don't have to change anything:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Ok, so, dabbling on my own, I can change the old segment 1 and 2 to the new segment 1 and 2 successfully with this:
# Changing location of old blog
Redirect 301 /old-template-group/old-page-template/ /new-template-group/new-page-template/
That works –but, of course, I’m left with the pesky “?”, and I can’t use that redirect function to do anything about it.
So, it seems I have to do more here -possibly with the original rewrite rule!
I would really, really appreciate some help on this! Although I can’t completely do a 301 redirect here because of the “?”, I can get close, and I can at least keep the older links to my page intact (which, I’m assuming search engines would treat more favorably!).
Thank you! -John Christian
UPDATE: It wasn’t “elegant”, but it’s probably the best way to do this since I had only a little over 100 channel entries…
I went to https://donatstudios.com/RewriteRule_Generator, and it allowed me to do a batch rewrite rule of all the entries. Basically, I first made a page on my old site that had all of the links from every channel, I copied them into excel, and I cut and pasted the new links in the column next to them (which yes, did take a while, but not too bad). Then, I just cut and pasted both columns straight into the generator! The guy has a “donate” button on his site, so I’m going to send him ten bucks or so! Ha ha!
Anyway, I wouldn’t want to do that with 40,000 entries, but I only had 104 so I could do it this way! It’s probably the “much better way” to do this, too, to ensure that the search engines KNOW that these are the new page addresses.
So, I still don’t understand the code, but his code actually took care of the “?” without breaking my css, etc. (unlike the other ones I found!). The “batch” part was icing on the cake. I hope my post helps someone else down the road!
-John Christian
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.