Redirect non-existing urls htaccess - .htaccess

I need to make in my web site redirections of non-existent urls using htaccess.
I explain, You must redirect all urls to one that contains some word that you enter.
For example:
Two existing urls:
https://www.example.com/this-is-a-house/
https://www.example.com/my-dog-is-pretty/
So if I type in the search engine a made up url, for example: - https://www.example.com/adasd-asduasnd-house/ it redirects me to hhttps://www.example.com/this-is-a-house/ because it recognizes that there is a word that matches that url.
If I type https://www.example.com/asdj-dog-asdg-kjmfwds/ it redirects me to https://www.example.com/my-dog-is-pretty/.
If the url is https://example.com/jkasn-llcmbxk-djfdinjg/ it does not recognize any word so it redirects to home.
Is it possible to do this?

Related

301 redirects specific pages with get parameters and non-specified pages

I have my old website old.com and my new website new.com. I want to create 301 redirects in the .htaccess for some specific pages and some generic 301 redirects as well.
Get parameter redirects:
old.com/a/test?u=blah redirect to new.com/a/test?u=blah
old.com/a/test redirect to new.com/a/test
old.com/a/test.php?u=blah redirect to new.com/a/test?u=blah
As you can see the only thing that changed was the domain name. How can I redirect users to the new domain but also keep their get parameter the same. So regardless of what u=, it forwards the u= parameter to the new URL. Of course if there is no u=, it still redirects to the page (as per second example)
Get parameter without putting get parameter
old.com/a/foo?u=blah redirect to new.com/a/foo
old.com/a/foo redirect to new.com/a/foo
old.com/a/foo.php?u=blah redirect to new.com/a/foo
As you can see, it directs to the new domain but does not carry the u= parameter. Same applies for the second example.
Redirect Directory
old.com/blog redirect to new.com/blog
old.com/blog/23452/how-to-tie-a-tie redirect to new.com/blog
If the site is in the blog directory, regardless of what comes after the blog directory in the URL, it always redirects back to new.com/blog
I am unsure on how to do these types of specific redirects. I only understand how to direct a specific URL like so Redirect 301 old.com https://new.com

Need help redirecting one website URL to another with apache2 and .htaccess

I have two domains - https://hosting.opensimcity.org, and http://paradigm.pocketmud.com and I want to redirect the latter to the former. That is, when someone connects to http://paradigm.pocketmud.com I want it to redirect to https://hosting.opensimcity.org/paradigm
Any tips on doing this in my .htaccess file?
Just try the following htaccess redirect code:
Redirect 301 / https://hosting.opensimcity.org/paradigm
This 301 redirect response notifies the search engines that the page has moved permanently from the old URL to the new URL. The search engines also transfer the old URL page rank to the new URL.

301 redirects not working properly. Numbers in URL being ignored

I have just replaced my old non-Wordpress site with a Wordpress site. Now I need to redirect approximately 400 old URLs to their equivalent pages on the new site.
I have already recorded all the old urls and new urls, but when I put the code in the .htaccess file I am getting a strange result.
If I try to redirect to any url that has a number in it, the redirect tries to redirect to that url minus the numbers.
For example:
Redirect 301 /international_organizations/africaamerica_institute http://nyintl.net/international-organizations-in-new-york/2792/africa-america-institute/
Redirects to http://nyintl.net/international-organizations-in-new-york/africa-america-institute/
Which isn't actually a page and thus returns a 404 error.
Anyone have any idea what's going wrong? All my posts on the new site have the month/year syntax in the url, so this means that 95% of my redirects aren't working.
All the urls that don't contain numbers are redirecting perfectly.
I have made sure to put all my redirects ABOVE the WP rewrite rules, but that hasn't made a difference (tried them below as well).

Mask URL to subdomain using IIS

I am looking to mask or cloak a URL with a subdomain.
For example, if I have the URL http://example.com/news/article/this-is-an-article it would be possible to visit http://test.example.com/this-is-an-article and the same page would display. Notice: the desired secondary URL is a subdomain of the original URL.
I am using IIS 7. All of the examples I have looked at only change the structure for the existing URL (instead of mapping it to a sub-domain). I am looking for something different to a redirect (perhaps a rewrite, if that is the correct term).
Assuming you are using the IIS rewrite module, there are two main response types: Rewrite and Redirect.
A rewrite takes the existing url and changes it internally within the same site, so that a url that doesn't really exist on the site is remapped to an existing endpoint. The user does not notice the difference, the requested url returns the expected content. This only works within a site.
A redirect is used when you need to return content from a different site (such as in your case). Instead of rewriting the url internally, a 301 or 302 with a new url is returned to the browser. The browser than just requests that new url and gets the content from the second site. The user will notice a change of the url in the address bar.
So you have to use the redirect response type in the rewrite module, only in this case you can specify an absolute URL such as http://example.com/news/article/this-is-an-article
If both example.com and test.example.com are mapped to the same IIS site, you could use a rewrite rule.

301 Redirect to URL with named anchor using IIS

I am trying to figure out how I can perform a 301 redirect from: http://www.examplesite.com/news to http://www.examplesite.com#news using IIS 6.0
Are there any issues associated with redirecting to a URL containing a hash that I should be aware of? Is it any different to performing a regular 301 redirect using IIS?
Thanks.
http://www.exmplesite.com#news is not a valid URL, so you redirect will fail. The hash sign (#) specifies that after fetching the page, the browser should scroll to the anchor with the name specified after the hash.
See http://en.wikipedia.org/wiki/Fragment_identifier

Resources