404 not FOUND when there is a dot(.) in the url (lighttpd) - .htaccess

I have a CodeIgniter app and have an .htaccess file with this code
RewriteEngine on
RewriteCond $1 !^(index\.php|file|test.php|lib|resources|xmlhttp|dashboard.html)
RewriteRule ^(.*)$ /index.php/$1 [L]
All urls are working fine except for this url
http://myweb.com/login?site=http://google.com
When I type that url in the address bar of a browser and press enter, I will get 404 NOT FOUND from lighttpd, and not from CodeIgniter (custom 404 error page)
The cause of the 404 NOT Found is the dot(.) from google.com bcause when i remove it, it is working as what i want
But when I use the url
http://myweb.com/index.php/login?site=http://google.com
It workds as i expected
My question is, is this because of the htaccess file? or apache configuration? or something else?
Any help or ideas will be greatly appreciated
Thanks

Related

htaccess - redirect 404 error

I would like to redirect in htaccess
https://www.example.com/albumgallery.php?id=8
to https://www.example.com/example-gallery
i've tried :
RewriteCond %{QUERY_STRING} ^id=8$
RewriteRule ^albumgallery.php$ https://www.example.com/example-gallery? [L,R=301]
-- it works , but on page it says
Not Found The requested URL /example-gallery was not found on this
server.
Additionally, a 404 Not Found error was encountered while trying to
use an ErrorDocument to handle the request.
any ideas what is wrong with that ?
You are getting a 404 not found error because www.example.com/example-gallery does not exist on your server. You need to rewrite this url to your existing url. for example when you type
https://www.example.com/albumgallery.php?id=8 into your browser your rule redirects it to https://www.example.com/example-gallery since this new url doesn't exist so your server returns a 404 error status. You need to add an internal RewriteRule to your htaccess to handle your new url.
Put the following right bellow your existing Rule
RewriteRule ^example-gallery/?$ /albumgallery.php?id=8&loop=no [L]
I added an additional perameter loop=no to the Rule`s destination it's to prevent infinite loop error so that the rule can not conflict with your existing RewriteRule.

Cannot implement a redirect to www url

I am setting up a new OpenCart store but have a problem with icons not appearing when I reach the site trough the URL that does not have www at the beginning.
I did a Google search and found out that I have to set up a redirect from the non www URL to the www one by modifing the .htaccess.text in my root folder. This is where the problem occurs, I cannot seem to find the right code to enter. The following is my current redirect code.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^eparhija\.com$
RewriteRule ^(.*) http://www.eparhija.com/$1 [R=301]
I have also tried other variants of this code bud none seem to work.
Any help would be appreciated. Also if it helps my website is www.eparhija.com
Rename .htaccess.txt to just .htaccess. Apache does not recognize the file with the .txt extension

htaccess not working, fails, if entered URL contains slash space slash. "site.com/ /"

I want to use a custom error page for ALL errors, so that there is no possible way that a visitor will see the servers built in error pages. But I seem to have found a glitch that I can not overcome.
The problem is that should a visitor mistype a URL with only spaces between two slashes, my environment seems to completely ignore my root folder htaccess file and sends the user to the built in error page.
The development environment is XAMPP on Windows 10. with the latest PHP & Apache etc.
To simplify the problem to it's root I am now using this HTACCESS File.
ErrorDocument 404 /statuspage.php
RewriteEngine On
RewriteRule ^ http://example.com [R=302,L]
The above code should redirect any and all URLs to example dot com. If that fails on not found pages, it should at least redirect to my error page. (which would probably then be caught and sent to example.com anyway.)
But when I type any of the following URLs, my entire project is ignored including the HTACCESS file and XAMPP throws out its own 404 error page.
1) www.mysite.com/ /
2) www.mysite.com/ /file.php
3) www.mysite.com/dir/%20/subdir/file.html
Apache replaces the space with %20. Ignores my redirect. And displays its own 404 page.
I should note that THESE errors are redirected just fine.
1) www.mysite.com/ file.php/
2) www.mysite.com/dir/ x/file.html
I realize this error would not be common. But it can happen and I'm struggling to understand what is happening and how to stop it.
This is because RewriteRule directive runs before the ErrorDocument . Your rule redirects all requests (including 404) to http://example.com . To resolve this , you need to use a RewriteRule instead of the ErrorDocument to redirect not found requests to /statuspage.php , Replace your ErrorDocument with this :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /statuspage.php [L]
After some research this seems to be a problem specific to my development environment.
My error log shows the error ID AH00127 When I Googled AH00127 I found that every single post involved a specific setup.
XAMPP for windows using a virtual host in the configs. I.E.
<Virtualhost *:80>
Since I will never use that on a live sight, the issue can be ignored.
Thanks to the responders.

How to redirect all page to 404 using htaccess

I want to redirect all pages on my site (including index) to 404 using htaccess.
Thanks in advance.
You can use this rule in root .htaccess file:
RewriteEngine On
RewriteRule ^ - [R=404,L]
The following works on newer apache:
Redirect 404
And you can add a message without creating a file like this:
ErrorDocument 404 "Hmm... There's nothing here..."

Problem in rewriting links with htaccess

I'm using this htaccess file to rewrite links,
RewriteEngine on
RewriteRule ^([a-zA-Z]+)$ file.php?show=$1
But I'm having problem so, when i go to the page I wanted after rewrite like this: http://somesite.com/mypage
It goes to that page successfully, but when you type a slash in the end of the link (http://somesite.com/mypage/) it doesn't open and says 404 error..
Please fix the code so I can enter pages with slashes or without
RewriteEngine on
RewriteRule ^([a-zA-Z]+)(\/)?$ file.php?show=$1

Resources