Htaccess rules: How to redirect to specificp page only if content inside a folder doesn't exist - .htaccess

I have this issue (I also searched through many threads but couldn't find the answer).
I moved a lot of content from principal domain to archives.
The action called firstaction used to have this link:
https://www.sitename.com/actions/firstaction (wordpress site)
and now it moved to
https://archives.sitename.it/actions/firstaction (totally different wordpress site).
But I still have a lot of content under www.sitename.com/actions/
So I want to redirect only if the content doesn't exist.
Only content under /actions/ folder.
I guess the redirect action could be something like
RedirectMatch "^/actions/(.*)" "https://archives.sitename.eu/actions/$1"
But I don't know how to add all the conditions I need.
I probably need to use the Skip flag S, but this goes beyond my abilities.
Thanks for your help!
p.s. it's a wordpress site under apache server.

Related

redirect numerous dynamic urls to home page via .htaccess

I am trying to clean up a previously hacked WordPress site, and domain name reputation, the site has new hosting and is now on a different CMS system, but there are hundreds of spam links in Google I need to get rid of, they look like example.com/votes.php?10054nzwzm75042pw205039
Domain name, then votes.php?**** etc.. Numbers letters all sorts.
So how do I redirect ANYTHING that starts with the domain name then /votes.php?***
Any help greatly appreciated
Unless you have multiple domains, you don't need to explicitly check the domain name.
To send a "410 Gone" for anything that contains /votes.php in the URL-path (and any query string), you can do something like the following at the top of your root .htaccess file using mod_rewrite:
RewriteEngine On
# Serve a 410 Gone for any requests to "/votes.php"
RewriteRule ^votes\.php$ - [G]
A 410 is preferable to a "redirect" if you want to get these URLs removed from the search engines as quickly as possible.
To expedite the process of URL removal from Google then use Google's Removal Tool as well.
If you redirect these pages to the homepage then it will likely be seen as a soft-404 by Google and these URLs are likely to remain in the search results for a lot longer.

Nginx URL rewrite to remove folder from URL when its followed by certain subfolders

After I have upgraded my site I see that once I go live with new version some parts of the website URLs will not be redirected for gallery, blogs and files because of new structure. And there is no way fixing it within the CMS. So my goal is to use NGINX redirects.
I wonder do any of you know any NGINX rewrite tricks to make such redirects possible?
website.com/forums/blogs/ into website.com/blogs/
website.com/forums/gallery/ into website.com/gallery/
website.com/forums/files/ into website.com/files/
I actually need the part forums dropped from the URL only and ONLY when the address is going for forums+blogs/gallery/files. Don't want to loose that google traffic.
So for example
website.com/forums/blogs/entry123/my-dog/ is redirected to
website.com/blogs/entry123/my-dog/
BUT
website.com/forums/topic/my-dog/
is left alone and working just like before because the following subfolder is neither blogs or gallery or files.
I needed that once on Apache and this one worked but on Nginx I have no idea.
RewriteRule ^forums/(blogs|gallery|files)/(.*)$ /$1/$2 [L,R=301]
You can try something like
rewrite ^/forums/(blogs|gallery|files)/(.*)$ /$1/$2;
Please note that rewrite directive accepts some flags wich meaning depends on where is it placed (is it inside a server or location block). Detailed documentation is here.

How can I display a subpage of my Silverstripe website as a subdomain?

I have a website build on Silverstripe 3.
Now I want that a user can enter the Subdomain URL info.mydomain.com and see the content of the page mydomain.com/subpage-url/. But without redirection. The subdomain URL should stay in their browser.
I already created the subdomain and let it point to the root directory of my website. As I understand it right I now need some rewrite conditions in my .htaccess file? And that is the point I struggle with. I googled a little bit and did some trail and fail but nothing seems to work. Maybe I understand it totally wrong, used the wrong rewrite conditions or insert them on the wrong place.. Maybe there are Silverstripe specific issues to pay attention to?
Long story short: I need help please!
As Robbie Averill pointed out in his comment, you could install the Subsites module. But you'd have to create a Subsite (eg. a separate site-tree) for every domain.
There's another module though, the homepagefordomain module. With that module you can specify one (or multiple) domains per page. When you visit one of these domains, the page that was specified as home-page for that domain will show up. I think this is a more flexible approach than messing with the .htaccess file.

Htaccess.. changing the domain name

I have a big Joomla website that was moved from .com to .eu domain.
The sites are on one web server.
On the old website there are a lot of links that point directly to oldwebsite.com/somethinghere.
Is there a way with Htaccess file in the old domains folder to redirect
from oldwebsite.com/somethinhere to newwebsite.eu/somethinghere?
Or maybe a way to do this on the new website folder?
Thank you,
Chris.
There are many ways, some people recommend using RewriteEngine, but there is an easier way:
Redirect 301 / http://domain.eu/
This will automatically handle files in the domain -- for example, old.com/foo will be redirected to new.eu/foo
EDIT: Regarding "301", that is the code for a permanent redirect. There also exist temporary redirects (I believe the code is 302), but it sounds like what you need is exactly this - a permanent redirect.
EDIT2: Oh and, I think the / after domain.eu may be required, but I'm not 100% sure - doesn't hurt for it to be there, that's for sure! I know that because I use the same kind of a redirect on a production website.

301 Redirect of Static HTML to Dynamic PHP Page

After upgrading our website, many old links that people have in blogs, etc. are now going to our 404 error page.
An example is: (using h#p b/c I'm a new user and can't post links)
h#p://www.site.com/pressreleases/some_release.html
h#p://www.site.com/pressreleases/another_release.html
These items are now part of a db-driven site and would be live here:
h#p://www.site.com/pressreleases/details.php?id=1
h#p://www.site.com/pressreleases/details.php?id=2
How can I set up the 301 to redirect
h#p://www.site.com/pressreleases/some_release.html
to
h#p://www.site.com/pressreleases/details.php?id=1,
and
h#p://www.site.com/pressreleases/another_release.html
to
h#p://www.site.com/pressreleases/details.php?id=2?
Thanks
Compose a .htaccess file in the pressreleases directory and specify the following:
Redirect 301 some_release.html details.php?id=1
If you would like to redirect using regular expressions, use mod_rewrite as explained here.
There are various options listed on this page.
If you have a lot of these URLs, and assuming you have access to the Apache config, consider creating a "redirects.inc" file in /etc/apache2 (or anywhere really) and then adding "include /etc/apache2/redirects.inc" to your virtual host. That way you have one place to add/update your redirects.

Resources