I've been given a request from a client to ensure all visits to their site are to lowercase URLs following an external SEO audit.
For example they'd like www.example.com/How-We-Help to redirect with a 301 code to www.example.com/how-we-help
Their site is hosted on WPEngine - I know this would be a simple thing to do using htaccess rules but htaccess has been deprecated on WPEngine for a little while now.
Example htaccess rule
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule . ${lc:%{REQUEST_URI}} [R=301,L]
I've read that it is possible to create a similar rule with Nginx rewrites but my knowledge is limited and WPEngine support weren't much help.
Is a way to do this using Nginx rewrites? If so, what rules need to be in place?
Related
We run a Wordpress Multisite installation with a about 15 different websites all on their own domain. On one of those sites we want to migrate to a new theme that uses custom post types and migrate some of the content to these new custom post types. Because of this migration some links will break, usually this is easily solvable with a 301 redirect in .htaccess.
The nature of a multisite install just gives us a single .htaccess and when I create a simple redirect like this:
Redirect 301 /testredirect http://www.testredirect.com
Every single domain will redirect this link to testdirect.com and not just the one we just migrated. Can we fix this in this single .htaccess or is there some other way?
The easiest option would probably be a switch to Mod_Rewrite, as you can add conditions (RewriteCond ....) to each redirection rule eg.
RewriteEngine On
RewriteCond %{HTTP_HOST} www.testredirect.com
RewriteRule /testredirect / [R=301,L]
We solved our troubles using the redirection plug-in for wordpress and some regular expressions: https://www.wordpress.org/plugins/redirection/
I'm having an issue with some htaccess rules which I thought would be simple. I have some nice SEO friendly URL rewriting in place as below
RewriteEngine On
RewriteCond %{REQUEST_URI} !^(index\.php|/images|/templates|/views|/ajax|/uploads|/robots\.txt|/sitemap\.xml|/favicon\.ico|/scripts|/cron|/combine.php|/js|/css)
RewriteRule ^(.*)$ index.php?ref=$1&%{QUERY_STRING} [L]
This all works well and I want to keep this. I also wish to rewrite some old pages which Google WMT is reporting as 404's to the new equivalent and for that I'd like to use:
Redirect 301 /about_us http://example.com/about-us
The problem I have is that the URL that the browser is directed to is:
http://example.com/about-us?ref=about_us
The about_us is the old link and about-us is the correct link. If the htaccess redirected to example.com/about-us then the other SEO friendly rewrite rule will pick it up and show the page but eh extra ?ref= parameter is confusing it. I am guessing the two rules are conflicting to a degree but is there a way to get the two rules to work together e.g. redirect without the extra ?ref= parameter? My knowledge of htaccess is basic to say the least so I am a little stuck on this one.
Thanks in advance
Redirect and RedirectMatch are part of mod_alias, while the rewrite rules are part of mod_rewrite. The problem you're running into is when you mix the two, both modules affect the same request, thus two things happen when you only want one. In this case, you need to stick with just mod_rewrite and use this instead:
RewriteEngine On
RewriteRule ^about_us /about-us [L,R=301]
RewriteCond %{REQUEST_URI} !^(index\.php|/images|/templates|/views|/ajax|/uploads|/robots\.txt|/sitemap\.xml|/favicon\.ico|/scripts|/cron|/combine.php|/js|/css)
RewriteRule ^(.*)$ index.php?ref=$1&%{QUERY_STRING} [L]
Note that the rule that redirects comes before the rule that routes to index.php.
I know there are some conflicts with my redirect and rewrite statements, but I haven't been able to find a solution. I am not great with regular expressions.
Currently, I have this:
RewriteRule category_(.*)-(.*)-(.*)-(.*)-(.*)-(.*)-(.*)\.html$ category.php?brand_name=$1&bid=$2&stid=$3&lid=$4&did=$5&sid=$6&sort=$7
It results in a page that similar to this:
category_Jackets-1-2-3-4-5-6.html
I want to now for SEO purposes, redirect that page to:
category_Womens_Jackets-1-2-3-4-5-6.html
I tried putting:
Redirect 301 /category_Jackets-1-2-3-4-5-6.html category_Womens_Jackets-1-2-3-4-5-6.html
But it resulted in:
category_Womens_Jackets-1-2-3-4-5-6.html?brand_name=Jackets&bid=1&stid=2&lid=3&did=4&sid=5&sort=6
I have tried using variations of Rewrite rule and Redirect to try to solve this, but no luck so far. I know the conflict is the issue, but I can't remove the original rewrite rule, or those pages would not work.
Any help would be appreciated.
The Redirect and RewriteRule directives are part of 2 different modules (mod_alias and mod_rewrite) and both will get applied to the same URI at different points. So you're rewriting AND redirecting at the same time. You should just stick with mod_rewrite to redirect if you're employing rewriting.
RewriteRule ^category_Jackets-1-2-3-4-5-6\.html$ category_Womens_Jackets-1-2-3-4-5-6.html [L,R=301]
The R=301 in the flags tells it to 301 redirect. You're going to want this before your other rule, and, your other rule is going to need to account for the Womens part.
I've tried many many methods of this but none seem to work.
I upgraded my site to PHP from ASP and as a result now I have 300+ 404's which i should of seen coming, but oh well.
Problem is I need to redirect these files and they are all dynamic:
old files are like: http://www.domain.co.uk/resoucecentreDetails.asp?title=foobar&ID=37
There are literally 100s of these so is there a quick way I can redirect them to a single page i.e. http://www.domain.co.uk/resoucecentreSelect.php
You can use Rewrite Rules in .htaccess.
Write following Rule in your htaccess.. It will redirect all your dynamic URLs to one page..
RewriteRule ^resoucecentreDetails.asp?title=(.*)&ID=(.*)$ /resoucecentreSelect.php [L,R=301]
This rule will do the job:
# activate rewrite engine
RewriteEngine On
RewriteBase /
# redirect rule
RewriteRule ^resoucecentreDetails.asp$ http://%{HTTP_HOST}/resoucecentreSelect.php [NC,QSA,R=301,L]
It will redirect all requests from /resoucecentreDetails.asp to /resoucecentreSelect.php preserving the query string, e.g.:
http://www.domain.co.uk/resoucecentreDetails.asp?title=foobar&ID=37
will become
http://www.domain.co.uk/resoucecentreSelect.php?title=foobar&ID=37
I am in the process of launching a full website that will be ready in about 6-9 months but I have a self-hosted Wordpress blog created in the meantime to start building a userbase and SEO. So since there will eventually be more to my site than a blog, my blog is located in a subfolder in my root domain (www.website.com/blog). I would like for my root domain (www.website.com) to automatically send users to my blog (www.website.com/blog). Once the full site is ready, I then want my users to enter my domain and be sent to the regular site and not the blog.
Through my searching, it seems like I will either have to set up a 301 or 302 redirect, which I understand how to do. The question is which one to use to prevent negative SEO once the full site launches. I have a feeling I should use a 302 redirect since it is a temporary redirect, but from what I have been reading, it seems like this may hurt my SEO on the popular search engines.
Your help would be greatly appreciated and I can provide more details if needed. Thanks!
I would suggest not to use external redirect and handle this via internal redirect only. That way your URL never changes and search engines will not index wrong URL. In your .htaccess put these rules for this purpose:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/+blog [NC]
RewriteRule ^(.*)$ blog/$1 [L,NE]
RewriteRule ^(/)?$ /blog [R=302]
That should do the trick.