Remove /page directory or /page.htm within .htaccess - .htaccess

Is there away within .htaccess file to redirect or hide a directory or page and have it display as Page Not Found, or an error?
I currently have an active Blog and do not want to remove it, but have /blog hidden if anything was to go to it.

Create a error page for example by name "404.html". And add this rule to the .htaccess file.
RewriteRule ^blog$ /404.html? [L,R=301]

Related

How to hide subdirectory from url without affecting index page of root directory

can anyone please me How to hide subdirectory from url in php using htaccess without affecting index page of root directory
suppose i have url https://evidhya.com/KSTA-Webinar i want to hide KSTA-Webinar subdirectory from url but it should not affect index page of the https://evidhya.com and i just want to display in url https://evidhya.com/-KSTA-Webinar and here -KSTA-Webinar is title of the page
I tried myself and found the answer it is working perfectly for me.
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^-KSTA-Webinar/?$ KSTA-Webinar/-KSTA-Webinar [L,NC]
Do you mean you only want -KSTA-Webinar to redirect to the real folder KSTA-Webinar? If so, you can just change your <a href='...' values to include the -, then add this to your .htaccess file:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^-KSTA-Webinar$ KSTA-Webinar/index.php [L]
...or whatever your file path is

htaccess redirect files with the same name to just one file (been hacked)

I would like your help to modify my .htaccess file. My site has been hacked and the malware has created thousands of pages and has really hurt my rankings. I have deleted the pages, but I want all of those links to redirect to one 404 page.
What do I need to write in .htaccess in order to redirect all of the pages that contain a certain word?
I have tried this
RewriteCond %{QUERY_STRING} ^(theword)
RewriteRule ^$ https://example.com/404.php [R=301,L]
But it doesn't seem to work: the 404 page I created appears, but the link still remains in the browser, just that now it's like this
http://example.com/404.php?theword=blablabla
Maybe because my site is on a wordpress platform?
I want all the pages that start with ?theword= to be redirected entirely and for the new link to appear /404.php not /404.php?theword=
Thank you in advance for your help!
The [QSD] (query string discard) flag added to your RewriteRule will drop the query string.

.htaccess RewriteRule Redirect works on htaccess tester, does not work on server

I have an .htaccess file defined at www.mydomain/documentation/.htaccess and am trying to redirect a number of broken links to a specific page.
The .htaccess file contains the Rewrite Rule
RewriteRule ^/?(documentation/PresentationCore~System\.Windows\.RoutedEventArgs).*$
/documentation/v4.x/SciChart_WPF_v4_SDK_User_Manual.html [R,L,NC]
Note: RewriteEngine ON has already been defined. Other rules are being applied
Now in .htaccess tester the rule is being evaluated and redirects correctly when the following URL is requested:
www.mydomain.com/documentation/PresentationCore~System.Windows.RoutedEventArgs~Handled.html
However, when the same domain is entered into the browser, I get a 404 not found for this page.
I can confirm I have uploaded .htaccess to the correct folder and cleared the server cache.
Is there anything else I need to do to get this to work?
You dont need to match the folder name if htaccess is already in that folder, try :
RewriteRule ^/?(PresentationCore~System\.Windows\.RoutedEventArgs).*$
/documentation/v4.x/SciChart_WPF_v4_SDK_User_Manual.html [R,L,NC]

Redirect home page htaccess, keep the rest

I have a Joomla site with a blog attached to it.
I created a new homepage for it, though, that uses just plain html and have uploaded it to the /new/ directory. I'm trying to write an htaccess redirect that will allow me to use the /new/ directory just for the homepage, but still use the Joomla part for the blog.
Here's what I have tried so far, but it doesn't work.
RewriteCond %{REQUEST_URI} !^/new/
RewriteRule ^ /new/ [L]
This actually redirects it in the browser to /new/ instead of doing it underneath the hood, invisibly. Also when I go to the /blog/ page, it is very messed up. In sum:
domain.com --> domain.com/new/ (but don't show the redirect)
domain.com/* --> allow joomla to do its thing
I couldn't get #anubhava solution to work, so I just moved my whole joomla installation into the /blog/ folder. There are just a couple of changes that you have to make in the configuration.php file. After that I put my new site in the root folder.

Mask folder in output URL

I have this website, it is my primary domain, however the folder is actually /public_html/annexation.ca. This part is fine, I have an htaccess rule in my public_html folder to deal with that, so that it shows up as annexation.ca and not annexation.ca/annexation.ca.
But I also run a forum off of that website. The problem is that the phpbb software has an auto-direct after logon, logoff and in a couple of other instances. And when it does so it generates a URL like this:
http://annexation.ca/annexation.ca/community
This is not only cosmetically disruptive, but it also impacts the comment section at the bottom of each unique page, where I have Disqus running. What I need is to add a rule to the htaccess file in the root folder that will make these redirects be automatically translated into this again:
http://annexation.ca/community/
Thanks!
Try adding this to your .htaccess
## 301 Redirect Entire Directory
Redirect 301 /annexation.ca/community(.*) /community/$1
You can try this rule on top of other rules:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+annexation\.ca/(community)([^\s?]+) [NC]
RewriteRule ^ /%1 [L,R=301]

Resources