complex htaccess rewrite - .htaccess

Before using word press for our new website we were using following urls...
http://www.domain.com/web-services
http://www.domain.com/seo-services (about 100 urls)
Now new url would be
http://www.domain.com/np/web-services
So we would like to 301 redirect all old pages to new pages, we could simple use following htaccess code...
Redirect 301 /web-services http://www.domain.com/np/web-services
But that would make htaccess file too large, so is there any way to redirect all pages to new pages.
thanks.

Enable mod_rewrite on your apache server, then put this inside your .htaccess file:
RewriteEngine On
RewriteRule ^/web-services/(.*)$ /np/web-services/$1 [R=301,L]
RewriteRule ^/seo-services/(.*)$ /np/web-services/$1 [R=301,L]
Any url starting with /web-services or /seo-services will be redirected to /np/web-services.

Or alternatively, you can use mod_alias' RedirectMatch:
RedirectMatch 301 ^/([^\-]+)-([^/]+)/?(.*)?$ /np/$1-$2/$3
So any request that starts with /web-services/ will get redirected with a /np appended to the front:
http://www.example.com/web-services/test1 -> http://www.example.com/np/web-services/test1
http://www.example.com/web-services/test/test2 -> http://www.example.com/np/web-services/test/test2
And the same with seo-services or anything with XXX-XXX.
EDIT:
if i try RedirectMatch 301 ^/([^\-]+)-([^/]+)-([^/]+) /np/$1-$2-$3/ its thorwing redirection error
Try:
RedirectMatch 301 ^/([^/\-]+)-([^/\-]+)-([^/]+) /np/$1-$2-$3/
Because /np/ is being matched against ^/([^\-]+)

You can rewite your domin like as if your domin was open with abc.com then you can permanently redirect it with www.abc.com. By doing this you can make sure that when google spider visit on your site then it can easily find your site. It also helps to increase more traffic on your site. If you have a busieness website then you can use SEO service from a company in Los Angeles going through reviews of best SEO Company in Chicago. Because these are helps to always push up your business growth towards top. Origin : http://www.bestseocompanyreviewss.com.

Related

301 redirect from one domain to another but only for specific pages

We are rebuilding a website for a client from ASP to WordPress. This website will have a different domain, url structure, and file extension. I am only just getting my head around htaccess 301 redirects, and I know enough that I can't do the following:
Redirect 301 http://www.site1.com/about_us.asp https://site2.com/about/
Redirect 301 http://www.site1.com/art-specs/ https://site2.com/specs/
Redirect 301 http://www.site1.com/page/product1/ https://site2.com/product1/
There are about 12 links in total that need to be redirected, and I want to make sure that it is done right the first time as a client's SEO rankings are on the line.
Is there a variation of the above format that I could use? Or a rewrite rule that needs to be done first? Any help (and explanations) would be greatly appreciated!
After looking more into it, I realised that the htaccess file shouldn't need anything other than relative access to the original domain.
i.e. You shouldn't need to declare: http://www.site1.com/about_us.asp since the server and domain should be configured in such a way that /about_us.asp means the same thing.
So the correct answer would be to:
[1] Configure the server (in my case cPanel) by having the original domain added as an addon domain (e.g http://www.site1.com/).
[2] In the htaccess file I would add each of the 301 redirects to the htaccess file:
Redirect 301 /about_us.asp https://site2.com/about/
Redirect 301 /art-specs/ https://site2.com/specs/
Redirect 301 /page/product1/ https://site2.com/product1/
...for each redirect
[3] And finally, adding the following to the bottom of the htaccess file will catch everything else and redirect them to the home page:
RedirectMatch 301 .* https://site2.com

How do I redirect a web URL using .htaccess

I want to redirect users who enter this website URL:
http://www.myWebsite.com/bananas
to:
http://www.myWebsite.com/fruits/bananas
I cant test it because I'm sending this to somebody.
I have these but I don't know for sure which one works:
RedirectMatch 301 http://www.myWebsite.com/bananas(.*) http://www.myWebsite.com/food/bananas $1
Options +FollowSymlinks
RewriteEngine on
rewriterule ^bananas(.*)$ http://www.myWebsite.com/food/bananas $1 [r=301,nc]
Please specify if you want to redirect or rewrite. The rules you are using serve different purposes and you used both in your example.
Redirect: Actually load a different site when entering the url (end up at url and content of /fruits/bananas)
Rewrite: Url stays the same but server provides rewritten content (url stays at /bananas, but show /fruits/bananas content)
http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
Also it is not clear if you only want one single directory to be redirected or all files that are contained in that directory.
Checkout this as a guide: http://www.htaccessredirect.net/
I believe you are looking for
Redirect 301 /bananas http://www.myWebsite.com/fruits/bananas
The HTTP 301 stands for Moved Permanently.
I haven't tested it, though.

htaccess redirect to another domain - specific pages then remaining to go to homepage

I am in the process of redirecting an old site to another domain. Using htaccess I have listed around 40-50 specific pages to be re-directed to it's equivalent on the new domain i.e:
redirect 301 /delivery.php http://www.newdomain.com/delivery/
redirect 301 /contact.php http://www.newdomain.com/contact-us/
redirect 301 /about.php http://www.newdomain.com/about/
redirect 301 /stores/finder.php http://www.newdomain.com/branch-finder/
...
I then have probably around 600-700 other links where i don't need them to go to a specific page, just the new domains homepage. Is there a way I can have a 'and all other pages go to homepage' line or command to just go to http://www.newdomain.com? Otherwise I will have to manually type and enter each one
Is there a way I can have a 'and all other pages go to homepage' line
Yes sure you can have this rule as your last rule:
RedirectMatch 301 ^/.+ http://www.newdomain.com/

Redirect directory to a subdomain

I have my domain pointed to a Rails app in Heroku, so for example, when you wanted to access some video, you would have an URL such as:
http://codigofacilito.com/video/W53XHWkbz34
We need to change that app to a subdomain, so the updated version would be:
http://videos.codigofacilito.com/video/W53XHWkbz34
What I want to know is:
Is there a way to redirect people to the new url with the subdomain videos by using the .htaccess file.
If you need this rule to only be applied to the video route, then give the following a try:
In your document root's .htaccess file, insert the following rule:
RewriteRule ^(video/.*)$ http://videos.codigofacilito.com/$1 [R=301,L,NC]
This works for me
RedirectMatch 301 ^/xxx/(.*)$ http://xxx.domain.com/$1
Using mod_alias:
Redirect permanent /video http://videos.codigofacilito.com/video
The keyword permanent causes Apache to send an HTTP status of 301 Moved Permanently instead of 302 Found.

.htaccess Redirect 301 Issue

I am having an htaccess issue that I cannot seem to figure out.
On my site I have several pages that have /wiget/ in the url.
.com/wiget/
.com/wigeta/
.com/wigeb/
.com/wigetc/
.com/shop/wigeta/
.com/shop/wigetb/
In my htaccess file I am using the following:
Redirect 301 /wiget/ http://www.site.com/content/wiget/
Redirect 301 /wigeta/ http://www.site.com/content/wigeta/
Redirect 301 /wigetb/ http://www.site.com/content/wigetb/
Etc.
What is happening, is that every URL with /wiget/ /wigeta/ /wigetb/ in it is getting redirected incorrectly. For example, these urls:
.com/shop/wiget/ is being sent to .com/shop/content/wiget/
.com/shop/wigeta/ is being sent to .com/shop/content/wigeta/
.com/shop/wigetb/ is being sent to .com/shop/content/wigetb/
What I want is only pages that have .com/wiget/ or .com/wigeta/ or .com/wigetb/ to be redirected to their .com/content/wiget{x}/ page
I am a rookie at htaccess and I cannot drum up the solution.
So basically you want to specify that your url have to start with /wiget/
RewriteRule ^/wiget/ /content/wiget/ [L,R=301]

Resources