My htaccess 404 rule is set as follows:
ErrorDocument 404 /404.htm
but this is what happens:
Non-existent url with no extension:
https://www.example.com/bgbgbgbgbg redirects to https://www.example.com/404.htm (correct behaviour)
non-existent url with a dot:
https://www.example.com/bgbgbgbgbg. redirects to https://www.example.com/404.htm (correct behaviour)
non-existent url with extension:
https://www.example.com/bgbgbgbgbg.htm redirects to "file not found" (should redirect to https://www.example.com/404.htm)
url endng with a slash:
https://www.example.com/bgbgbgbgbg/ redirects to a weird 404 page with no css, and the urls in the browser's address bar does not change (should redirect to https://www.example.com/404.htm)
I did some research and tred implementing these lines right under ErrorDocument 404 /404.htm:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . https://www.example.com/404.htm [L]
it solves everything, BUT it redirects the homepage (https://www.example.com) to https://www.example.com/404.htm
What can I do in order to solve the homepage issue?
To redirect non existent requests to 404 error page you can simply use :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.+$ /404.htm [L,R]
Related
my url
www.mysite.com/content
How can i redirect my site if type wrong URL like this
www.mysite/contentfasfsa(any letter)
That would redirect to original site www.mysite.com/content/ how could i do that.
You will have to edit your .htaccess file. There are two ways for doing this :
1. ErrorDocument 404 /content (Your home page)
This will redirect all the error 404 to your homepage.
2. RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ www.mysite.com/content [L]
This rewrite rule will redirect broken links to your homepage.
Try them out.
I want to redirect 404 page to search page.
For example,
example.com/url - if this url is not found then redirect the url in the format:
example.com/index.php?page=search/web&search=[url]&type=Web&fl=0
It has to be done with htaccess. I was not able to achieve this with htaccess.
Try the following rule in root/htaccess :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /index.php?page=search/web&search=$1&type=Web&fl=0 [NC,L,R=301]
I have all my customers sites on a subdomain
customers.example.com/sites/customer_name
I have Them made a htacces URL rewrite, so the users only need to enter
customers.example.com/customers
Almost everything works fine, except when I go to a joomla backend
customers.example.com/customer_name/administrator
Then the CSS disappears. I don't know I it's a joomla error or just me doing something wrong
This is my .htaccess file
RewriteEngine On
ErrorDocument 404 http://jdeweb.dk/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /sites/$1/ [L]
I'd like to ask - is there a way to auto redirect with httacces conditions when rewrite rule doesn't exists?
For example.
I have the following rules:
RewriteRule ^/index/$ index.php
RewriteRule ^/error-404/$ 404.php
ErrorDocument 404 /error-404/
When someone will try to access adress like index/something-added-by-user/ he will see 404 page, but url will be still "index/something-added-by-user/". Is there a way to automatically redirect from that url typed by user to url "error-404/"? So when he type url like above, he will see 404 page with 404 page url.
It can be done using this rule:
# not a real dir
RewriteCond %{REQUEST_FILENAME} !-d
# not a real file
RewriteCond %{REQUEST_FILENAME} !-f
# not a real link
RewriteCond %{REQUEST_FILENAME} !-l
# redirect it to 404.php
RewriteRule ^ /404.php [R,L]
Though keep in mind that browser will not get 200 status instead of 404.
I have a site which runs from a sub directory - hosted on HostGator. Most of the htaccess rules work to redirect to the sub directory except for one.
if i go to example.com/products - I get an invisible redirect to example.com/subfolder/products - it appears correctly in the address bar as example.com/products
however if i go to example.com/news - I get a visible redirect to example.com/subfolder/news - it appears in the address bar incorrectly as example.com/subfolder/news
The following is the .htaccess code I am using in my root folder:
RewriteEngine on
RewriteRule ^$ /subfolder/ [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subfolder/$1 [L]
For reference: If I type example.com/news into the browser I am visibly redirected to example.com/subfolder/news - however if I type example.com/news into the browser a second time I am invisibly redirected!
Google has crawled the site and is serving the visible redirect urls (so they appear in Google as example.com/subfolder/news)
UPDATE:
In that .htaccess file the only other line I have it Options -Indexes
In the subfolder .htaccess file I also have
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L,QSA]
ErrorDocument 403 http://www.example.com/403
ErrorDocument 404 http://www.example.com/404
ErrorDocument 500 http://www.example.com/500
I'm with HostGator if that would have any bearing?