How to add a 404 for a specific URL in htaccess - mod-rewrite

I have a page at http://www.example.com/my-inner-page. I need my server to respond with a 404 when someone tries to access this url. What is the rule I would use in htaccess to accomplish this?
Thanks!

You can use RedirectMatch:
RedirectMatch 404 "my-inner-page"

Related

Redirect 301 a single URL using htaccess or routes.php

I am trying to redirect /es/services to /es/servicios but I'm unable to do it, I've tried on .htaccess with
Redirect 301 /es/services mydomain.net/es/servicios
But nothing happens, also wanna say only on /es language so how can I do it?? I'm using laravel 5.5
Thanks!

How to redirect to https when user type http in codeigniter

I need to redirect my url to https when someone write my url on browser. The problem is when I write my website name on browser with https its working fine showing secure lock. But when I am trying to type myurl.com on browser it will redirecting to http not https. I need to type https before my website url on browser to redirect it on secure lock. How can I redirect it into https automatically when someone write my website url. I have done everything change countless time my htacess file but nothing fix this issue.
Thank You
If you want to add http -> https in your CodeIgniter without configuring .htaccess, you can add following in application/config/config.php before $config['base_url']:
if($_SERVER['REQUEST_SCHEME'] == 'http') {
$web_path = $_SERVER['HTTP_HOST'] . str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
header('Location: https://'.$web_path);
die;
}
This is not a good way to go but can help you until you identify why webserver isn't reading your .htaccess file. What above code does is, it checks if request came for http, if yes, it creates variable $web_path with incoming source path and redirect same with https scheme.
Best way to do this is from .htaccess.
Try this -
RewriteEngine On
RewriteCond %{HTTP_HOST} ^myurl\.com$
RewriteRule (.*) https://www.myurl.com/$1 [R=301,L]
This will work as you expected.
This will pass all the possible combinations and redirect to https://www.myurl.com -
Url without https - (http://www.myurl.com)
Url without www - (https://myurl.com)
Url without https and www - (myurl.com)
Please try this. Hope this will work. Thanks.

How do you 301 redirect 404 errors on a Magento website?

We have an e-commerce website built on the Magento platform at vaperempire.com.au and would like to automatically 301 redirect all 404 errors to the homepage. How would we go about doing this?
Thanks in advance to all those who help!
ErrorDocument 404 /index.php <--- Your home page
Try this on your .htaccess file. Carefull though because 404 responses are completly normal and let you diagnose bad urls on your webpage.
If there are only a few you can try this.
Redirect 301 /oldpage2.html http://www.yoursite.com/folder/

How to redirect few urls http to https?

I have tried searching here but nothing worked for me. I have Joomla site and want to redirect some site urls (3-4) to use HTTPS traffic to process credit card payments. Can you please guide me how can i do it using .htaccess file? what would be the exact code?
I do not want whole site to run over ssl https but few pages.
I want these:
http://www.domain.com/city1/store
http://www.domain.com/city2/subcity/store
to use https.
Thanks
Maybe try this:
RewriteRule "^/folder(/.*)" "https://%{HTTP_HOST}$1" [R=301,L]
Look more on htaccess HTTPS

joomla - SEO settings and mod_rewrite

I'm using Joomla 1.5.14 and I configured SEO as in the following image
Now I need to map a few old URL to the new site
let's say that I need to map htp://mysite/old.html to the new Joomla page
http://mysite/index.php?option=com_content&view=article&id=32&Itemid=70
I added in my .htaccess file the following
RewriteRule ^old\.html$ index.php?option=com_content&view=article&id=32&Itemid=70 #works!!
this works fine, but if I use the SEF URL in .htaccess (let's say the above page can be reached with htp://mysite/contacts.html), I obtain a 404 error
RewriteRule ^old\.html$ contacts.html #this does not work
Now the question:
Is it possible use SEF URLs in RewriteRule? where am I wrong?
thank you in advance
stefano
I think the problem is because Apache rewrites old.html to a page that doesn't actually exist, but rewritten in a different rule.
If you truly want to "rewrite" - in other words, have the page stay as old.html in the browser - then you don't need to do anything.
However to avoid duplicate content it's probably better to do a 301 redirect:
Redirect 301 old.html http://yoursite.com/contact.html
(You may need a forward slash at the front of old.html)

Resources