If you decide that you want to move your business website between content management systems.
You might want to ensure that your old links to specific content are still accessible.
Some examples being blog posts, images or downloads.
Following are two .htaccess hacks to
- firstly provide a download link that matches the old location without reproducing the original directory structure and also
- redirecting content from one URL to another with a permanent redirect.
Making Download Content Seamlessly Available from the old URL but put the content in another directory
The old server had files stored in /var/www/example.com/sites/default/files/
and you accessed them using a URL like this http://example.com/sites/default/files/vpnclient.exe
The new server has a web root of /var/www/example.com/public_html
And I want to put download files in /var/www/example.com/public_html/downloads
avoiding the previous CMS's deep directory structure
So to get your old URLs to work you put some rewrite rules in your .htaccess
file in /var/www/example.com/public_html
RewriteCond %{REQUEST_URI} "^/sites/default/files/.*$" [NC] RewriteRule "^sites/default/files/(.+)$" "downloads/$1" [PT]
The above code will make sure that the client won't be redirected but the web server will serve the file on the old URL from the new location of the file in the downloads folder
Redirecting Clients and Search Engines to new URL's
The next .htaccess
hack is making sure that your blog posts from the old URL scheme (Drupal) are properly redirected to the new content on the new CMS (Joomla).
Redirect permanent /blog/going-above-and-beyond http://example.com/about-us/blog/128-going-above-and-beyond # or with RedirectPermanent RedirectPermanent /blog/going-above-and-beyond http://example.com/about-us/blog/128-going-above-and-beyond
The permanent keyword makes the web server issue a 301 "Moved Permanently" redirect which apparently Google and other search engines take as a sign that the search engine ranking for the old URL /blog/going-above-and-beyond should now apply to the new URL http://example.com/about-us/blog/128-going-above-and-beyond
You can add as many Redirect statements as needed but if you have many hundreds of URLs to remap you may want to look at using RedirectMap or regular expressions to achieve this without making .htaccess too big.
0 Comments