Too many wordpress redirects - wordpress

I've inherited a page with a large multi-step form at /big-form that's passing fields to each subsequent step via POST. I need to make each step more SEO friendly, something like /form/step-[1-5]. It would also have /other-form/step-[1-5] on the same page.
I added this RewriteRule:
RewriteRule ^form/step-[1-5] /big-form/ [QSA,L]
which should push requests for the SEO pages to the already created page, but it 404s. Looking through the redirect logs, it's catching the /form/step-1 url, redirecting that to /big-form, then doing the usual wordpress redirects through /index.php. For some reason, by the time WordPress is looking for what page to render, it's getting confused and giving up.
Is there a way to redirect all requests from the SEO friendly URLs to the actual page in WordPress?

Assuming the site does not contain any other URLs containing "step", you could just do:
RewriteCond %{REQUEST_URI} step
RewriteRule .* /big-form/ [R=301]

Related

.htaccess - Combatting String Query Spam, Custom 404 redirect

Been trying to clean up the aftermath of a decode64 content injection hack on multiple sites on my shared server.
It's clean, but now I'm getting links of incoming spam links with query string, like abc.com/?some-stupid-porno-spam/, so even though the content no longer exists, they're still being redirected to the front page. Am ranking for these spam words instead, or google's just saying those are soft-404s for the luckier sites.
Got a solution, but it's temporary. I was advised to add the following to the top of the .htaccess file:
RewriteEngine on
RewriteCond %{QUERY_STRING} .
RewriteRule ^/?$ - [L,R=404]
So, now all links with /? are redirected to a 404. 2 problems:
It's temporary, in that ALL /? queries are thrown to the 404, including wordpress post/page previews. Is there are way to make it such that it only works for non-existent pages?
The 404 points to the webhosts 404. How can I make it such that it goes to the theme's 404 instead?
Thanks for your time!
------ update
So, the above code works great. I can preview posts/pages, but I found there's a problem - it blocks wordpress' WYSIWYG text editor. The 'visual' tab remains blank, and none of the toolbars appear.
Help? lol

How to redirect a domain to a web page?

I have a Wordpress website => www.mywebsite.com
where I can create pages such as : www.mywebsite.com/page-hello.html
I also have a domain : hello.com
I would like to redirect the website hello.com to the page www.mywebsite.com/page-hello.html while keeping hello.com in the URL.
Basically hello.com stays in the UTL but users will see this page > www.mywebsite.com/page-hello.html
I don't think I've come across such scenario where the page being viewed will be different from the URL. If you have, please let me know.
There are two ways you can redirect the hello.com to the page www.mywebsite.com/page-hello.html.
1. Depending on your hosting company, but I think it is common for all hosting companies to have the domain redirection function. Log in to your control panel, under the domains section, you should find a link to add domain redirects. See attached image.
You can do this through your .htaccess file. Locate this in your root folder (public_html), and then add the code below:
# .htaccess
RewriteEngine on
# Require www
RewriteCond %{HTTP_HOST} ^www.hello.com$ [NC]
RewriteRule ^(.*)$ http://www.mywebsite.com/page-hello.html/$1 [R=301,L]
Hope that helps.

How can I use htaccess to redirect paths with a wildcard character in wordpress

I recently changed my 92 category links and now I am getting hit with hundreds of 404 errors from Google because the old links are not found. I tried to use plugins to automatically redirect single URLS but I am noticing there are more and more coming in and doing everything on a 1 by 1 basis is not efficient.
I was hoping someone could assist me on getting my pages redirected using my htaccess file.
For Example Going to
example.com/category/old-category/
should redirect to
example.com/category/new-category/
More importantly I would like to redirect the page numbers of the old categories to the page numbers of the new categories using a wildcard. So page x of old category will redirect to page x of new category.
example.com/category/old-category/page/5/
should redirect to
example.com/category/new-category/page/5/
Thanks in advance.
You can use this generic redirect rule just below RewriteEngine line:
RewriteRule ^(category)/old-category(/.*)? /$1/new-category/$2 [L,NC,R=301]

domain redirect to a page and rewrite url of landing to keep orgin domain

this it might be easy but I'm not sure how to achieve it (nor if it's actually possible..)
I've made a page in wordpress, with a custom template design, and not linked with the rest of the website, so it's a landing page which actually has nothing to spare with the base website.
I've bought a domain and redirected with a 301 to this page (to pass seo from that page as well).
the problem is that now I'd like to have the url of that page rewritten in order to be the same of the one I've bought, so when landing in that page, viewers won't notice that they are in another domain.
basically I want that a domain like this
my-new-domain.com
which redirects to this page (I've done this)
maindomain.com/landing-page/
and once you're there, the url displayed is:
my-new-domain.com
the page is wordpress, so I need it to keep passing the variables while the url is rewritten.
but I don't need it to handle sub-pages, as the page is a single landing page.
can I do this with an htaccess rule? and if yes, could you please tell me how this rule should ne written?
Thanx to anyone who'll help!
Andrea
You could use mod_rewrite for this
RewriteCond %{HTTP_HOST} my-new-domein.com [NC]
RewriteRule ^ /landing-page [L]
The first rule is the condition, so if the domein (http host) matches your domein the second line get executed, [NC] means no case, so my-new-domain.com and MY-NEW-DOMAIN.com both work
The second rule has 3 parts
^
as another condition (always matches)
/landing-page
that's the page which is passed to wordpress
[L]
means this is the last rule to be executed, handy when multiple rewrite rules at in the .htacess
Edit:
In addition, if you want mydomain.com/landing-page to show it's content but with my-new-domain.com in the url bar use the following to redirect to my-new-domain.com
Redirect 302 /landing-page http://my-new-domain.com

Forwarding homepage to landing page using htaccess

I have a Wordpress site (eg. www.domain.com) that lands on the homepage. I want to change this, so it actually lands on an interior page (eg. www.domain.com/landing/). I don't want to do a standard redirect, as I still want to allow access to the homepage. I just want to change the initial landing page.
I'm assuming it's a matter of updating the ".htaccess" file, but I just want to find a solution that will still allow me to access the homepage of the site, once I've landed on the landing page.
You can do this in the wordpress dashboard/customise your site. Set your static front page to the new landing page.
Try checking the referer to make sure it's either someone who typed the URL in the address bar or clicking a link elsewhere:
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^https?://(www\.)?domain\.com [NC]
RewriteRule ^$ /landing/ [L,R]
You'd want this above your wordpress rules.

Resources