Issue
Our site was recently migrated from a basic php/mysql app to Wordpress. In the old app, we had content in a subdirectory which is now located on a new domain.
Examples below.
Old link:
https://example.com/vibes/vibin.php?showsomething=abcd&whatever=whatever
Should redirect to:
https://vibes.com/vibin.php?showsomething=abcd&whatever=whatever
The complicated angle is that the Old links are now a Wordpress installation. In the default .htaccess
file of wordpress I see the following:
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I've poked around in the WP admin area but don't see how I'd safely edit that file.
Is there another way around this or are will our users just have to update bookmarks the old way?
Solution
htacess
You can edit the .htaccess file by hand using ftp and add the redirect that you want. Make a backup first. If you want to avoid ftp access then I don't recommend updating the .htaccess file at all because you'll need that access if you break something.
You could use a WordPress plugin to edit the .htaccess file to avoid ftp access, like "Htaccess File Editor." (Please make sure you have ftp access before you try this so you can put your backup back into place if it breaks.)
If you want to redirect all requests then I would look here https://serverfault.com/a/280067 to see how to create a redirect using .htacess that redirects to another domain and also keeps the query string. Maybe it would look something like this.
RewriteCond %{HTTP_HOST} !^vibes\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/?(.*) http://www.vibes.com/$1 [L,R,NE,QSA]
If you want to only redirect requests to a certain URL on the old site, then I would look here https://stackoverflow.com/a/8416095/222564. Maybe it would look something like this.
RewriteBase /
RewriteRule ^vibes/(.*)$ http://www.vibes.com/$1 [L,R=301,QSA]
plugins
Since the old website is running WordPress, instead of editing .htacess you could use a plugin to redirect requests. There are various "redirect" plugins available. For example "404 Solution" has an option to redirect requests based on a regular expression to another domain and keep the query string. I maintain that plugin so I know it does that, but I don't know about the other plugins.
For example you would redirect from /vibes/(.*)
to http://www.vibes.com/$1
Answered By - AaronJ
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.