How to URL rewrite a moved site from wordpress? - wordpress

I moved my site from wordpress to another platform. I tried to rewrite the old urls without success.
previously I had url structures similar to examples down below...
domain.com/category/post-name.html
domain.com/category/page-name
domain.com/category/post-2010-name.html
domain.com/2011/02/16/post-name.html
domain.com/2011/02/16/page-name
as you can see above sometimes the postname had a number to it. Also, pages and posts were listed with dates.
the new url structure is...
domain.com/brand-new-section/blog/
so old url...
domain.com/mobile-phones/new-iphone-5-maps-issue.html
should map to...
domain.com/brand-new-section/blog/mobile-phones/new-iphone-5-maps-issue
so, I did the url rewrite for dates...
RewriteRule ^/[0-9]+/[0-9]+/[0-9]+/(.*)?$ domain.com/brand-new-section/blog/$1 [R=301,NC,L]
Any suggestions?
how can I combine the above url rewrite with other rewrite rules such as... domain.com/category/post-name.html
domain.com/category/post-2010-name.html
tried...
RewriteRule ^/[0-9]+/[0-9]+/[0-9]+/(.*)?$ http://www.domain.com/brand-new-section/blog/$1[R]
RewriteCond %{REQUEST_URI} ^/[a-zA-z]+/[a-zA-z]+/(.*)?\.html$
RewriteRule ^/[a-zA-z]+/[a-zA-z]+/(.*)?\.html$ http://www.domain.com/brand-new-section/blog/$1 [R=301,NC,L]
no success.
thank you.

Related

Apache HTAccess Remove Query String for redirect

It sounds like a relatively simple one but here goes.. I have a wordpress website called example.com It has recently been redeveloped using wordpress however the old sites structure used the following www.example.com/?page_id=22 I want to redirect anything after the domain name that contains /?page_id=[any digit] to the homepage, im having great difficulty in accomplishing this and I also think I may have issues because wordpress itself uses the query string page_id before the permalinks redirects kick in, I could be wrong though but any help on removing the query string directly after a domain name would be great especially keeping in mind that it is a wordpress install.
I have tried various iterations that look like the following to no avail
RewriteCond %{QUERY_STRING} ^page_id=(.*)$
RewriteRule (.*) http://www.example.com/ [R=301,L]
RedirectMatch 301 ^/page_id=(.*)$ /
Try this rule right at top, just below RewriteEngine On line:
RewriteCond %{QUERY_STRING} ^page_id=\d+$ [NC]
RewriteRule ^/?$ /? [R=301,L]
/? will strip off any query string.

Doing 301 redirects of urls containing a specific string caused by hacking

I have a wordpress site that was hacked and hundreds of urls were created that no longer exist after I cleaned the site up. I have noticed a lot of these urls contains a specific keyword as displayed below
http://www.capecrossfit.com/kamagra-holland/ - I need to rewrite all urls containing the word kamagra to http://www.capecrossfit.com/ - I have tried all the recommendations on near similar requests on this site with no joy, can anyone please advise how this can be done with htaccess?
Pace this rule as very first rule (just below RewriteEngine On line):
RewriteEngine On
RewriteCond %{THE_REQUEST} /kamagra-holland|buy-kamagra-europe|kamagra-super-jelly [NC]
RewriteRule ^ / [L,R=301]

redirect a domain extension to a subdirectory

I am trying to create a permanent htaccess redirect (301) from all my domain extensions into the appropriate subdirectories. The "rules" are as follow:
Redirect belgian website to its subdirectory on the main website:
from: www.example.be
to: www.example.com/befr/
Of course I would like to preserve the url parameters (if any) of the "from". Globaly, if someone entered the first url it should redirect to the second url (langage subdirectory in the main website).
I'm using wordpress and I'm hosting on a plesk I've read many things here but I'm stuck, thank you very much in advance for your help
PS: I've tried that but it doesn't work
RewriteCond %{HTTP_HOST} ^(www\.)?example.be$ [NC]
RewriteRule ^(.*) http://www.example.com/befr/$1 [L,R]
After reading your question, your code should be working (with informations you gave).
If it's not, here are some points to check:
1. Make sure mod_rewrite is enabled and htaccess can be executed (Apache config).
2. Your htaccess has to be in root folder (where example.be is forwarded).
3. About your htaccess' code:
since you're using Wordpress, make sure your rule is on top of other rules
don't forget to escape . (second one) in RewriteCond (otherwise it doesn't mean the same) even if it works that way
replace R flag (302 by default) by R=301 if you want a 301 redirect
Your code now looks like this
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example\.be$ [NC]
RewriteRule ^(.*)$ http://www.example.com/befr/$1 [R=301,L]
# your other rules (and Wordpress' default rule) here

htaccess url rewriting question

I have a site made with CodeIgniter with a WordPress site at /blog.
Say I create a page in WordPress that can be viewed at /blog/my-page.
Is it possible to rewrite the URL with .htaccess to remove the blog part of the URL? So I could enter my site url /my-page to view the page?
from the top of my head..
#start the engine
RewriteEngine on
#requests to www.yourpage.com/anything/
RewriteCond %{REQUEST_URI} ^/([^/]+)/?$ [NC]
#are sent to www.yourpage.com/blog/anything/
RewriteRule .* /blog/%1 [L]
The rule below will rewrite (internal redirect) /my-page to /blog/my-page:
RewriteEngine On
RewriteBase /
RewriteRule ^my-page$ /blog/my-page [NC,L]
RewriteRule ^another-page$ /blog/another-page [NC,L]
This needs to be placed in .htaccess in website root folder.
If you already have some rewrite rules there then this one need to be placed in appropriate place as order of rules matters.
You still may need configure WordPress a bit so it understands that this URL is for him to process (WordPress may still see the original URL). I have not worked with WordPress that much to tell if this will be required (and how to do it if it is) -- but look at Permalinks settings.

Does anyone have experience simultaneously running a Drupal and Wordpress site and redirecting some links from Drupal to Wordpress

This is a really weird question and I apologize:
I've been asked if it's possible not to import our blog from Wordpress to Drupal but just keep it in Wordpress as an archive and re-direct our users say from hostname/blog/... to hostname/wordpress/... when a URL matches the Wordpress URL pattern.
I've never heard of anyone trying this and I'm wondering about pitfalls and whether or not it's even possible.
Thanks!
D
This looks like it should be pretty simple to do. I plan to take advantage of the mod_rewrite module for apache:
We will just need to configure a .htaccess file to redirect URLs matching hostname/blog/pattern/ - where pattern fits a Wordpress URL blog pattern.
I use mod_rewrite on my Drupal site. Here's an example I use to redirect users to www.earldouglas.com when they access earldouglas.com:
RewriteCond %{HTTP_HOST} ^earldouglas.com [NC]
RewriteRule ^(.*)$ http://www.earldouglas.com/$1 [L,R=301]
You could try something like the following:
RewriteCond %{REQUEST_URI} /blog
RewriteRule ^(.*)$ /wordpress [L,QSA]

Resources