Htaccess "not file" (!-f) mistakenly matching file name - .htaccess

My htaccess file is mistakenly matching the following url as a file.
www.mysite.com/robots/robot-name/1
In my root directory, like any other site, I have a robots.txt file that is messing the htaccess up.
.htaccess
RewriteEngine On
RewriteBase /htaccess
DirectoryIndex index.php
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.*) [NC,OR]
RewriteRule ^([a-zA-Z0-9_-]*)(/?)(.*) index.php?page=$1&vars=$3 [NC,QSA,L]
How can force the %{SCRIPT_FILENAME} !-f to match a complete file name?]
Thanks in advance.

FIXED! Thanks to PanamaJack for the help. I just disabled MultiViews and problem solved. Final htaccess bellow:
Options -MultiViews
RewriteEngine On
RewriteBase /htaccess
DirectoryIndex index.php
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.*) [NC,OR]
RewriteRule ^([a-zA-Z0-9_-]*)(/?)(.*) index.php?page=$1&vars=$3 [NC,QSA,L]

Related

Multiple htaccess rewrite conditions and rules?

Having some issues when adding a new condition and rule to my htaccess file. We are needing to redirect traffic from a specific referral domain. Existing htaccess looks like this:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /~bayour8/
RewriteCond %{REQUEST_FILENAME} .*\.(jpeg|jpg|gif|png)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /~bayour8/public/404.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /~bayour8/index.php [L]
#suPHP_ConfigPath /home/bayour8/public_html
</IfModule>
I need to add something like this but it never processes it:
RewriteCond %{HTTP_REFERER} !^http://domainx.com [NC]
RewriteRule ^/?first-page.html$ http://www.domainy.com/pages/pagename/ [L]
Any assistance would be appreciated!

url rewriting not showing index page

I have this htaccess file:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
DirectoryIndex index.php
RewriteRule ^doit$ doit.php [L]
RewriteRule ^([\$\.A-Za-z0-9_-]+)$ follow.php?follow=$1 [QSA,L]
But when i try to go in the index page, everytime showing follow.php page, even doit page show this last one.
Any fix for this issue please ?
Thank's.
RewriteCond technically applies only to the first RewriteRule, so
please try using something like this:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([\$\.A-Za-z0-9_-]+)$ follow.php?follow=$1 [QSA,L]
#RewriteConds for this rule
RewriteRule ^doit$ doit.php [L]
DirectoryIndex index.php
I hope be useful. Regards.

.htaccess allow domain.com/sub to be browsed to, but also make somethingelse.domain.com go to that same folder

I'm in need of assistance with mod_rewrite. Currently, I've a folder at www.domain.com/folder. I need to leave the files where they are, but have the address bar in the browser appear as someothername.domain.com
Any help would be greatly appreciated!
I should mention that I've already got a few .htaccess rules in place, as shown here:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.+)$ index.php?$1 [QSA,L]
Thanks in advance,
-Ray
You can have 2 .htaccess like this:
DocumentRoot/.htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^((?!folder/).*)$ folder/$1 [L,NC]
/folder/.htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /folder/
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.+)$ index.php?$1 [QSA,L]

.htaccess retrieve from folder if subdomain, not 301 redirecting?

I want my site to just point to /user folder if the request is a subdomain.
If the request is subdomain.site.com/admin, then the site should show the page for subdomain.site.com/user/admin.
The problem with my code is that it makes an 301 redirect instead of just keeping the url-address.
My code look like this:
<IfModule mod_rewrite.c>
DirectoryIndex index.php
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.bildsida.se(.*)
RewriteCond %{HTTP_HOST} ^[^.]+.bildsida.se(.*)
RewriteRule ^$ user/$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) user/$1 [L]
</IfModule>
And you can try for yourself, go to http://mickes.bildsida.se/admin and see how the address changes to /user/admin. Very disturbing...
You just need a few of the lines you showed to get this working.
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.bildsida.se
RewriteCond %{HTTP_HOST} ^.+\.bildsida\.se
RewriteRule ^(.*)$ user/$1 [L]
I adjusted the HTTP_HOST checks because that parameter only looks at the domain name, so you don't need the (.*) at the end. I also removed the checks that look if the file exists or is a directory, since you want everything redirected (no reason to make it possible to access files from other subdomains, for example)
You code can be simplified to these lines : (try them instead)
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www\.)?bildsida\.se [NC]
RewriteRule ^(.*)$ /user/$1 [QSA,L]
Finally! After days and nights of reading forums and documentations, and testing all possible ways, I got it to work!
Sulotion:
<IfModule mod_rewrite.c>
DirectoryIndex index.php
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.bildsida.se
RewriteCond %{HTTP_HOST} !^bildsida.se
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^$ user/index.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)? user/$1/ [QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule /(.+)/ user/$1 [QSA]
</IfModule>

Force htaccess to redirect for specific requests

I have the htaccess file
Options -Indexes +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])/?$ /index.php?p=$1 [L,QSA]
How can this be changed to force requests to /sys-admin to be redirected into index.php even if it does exist (file or directory)?
Add another rule set:
RewriteCond %{REQUEST_URI} /sys-admin*$
RewriteRule ^(.*[^/])/?$ /index.php?p=$1 [L,QSA]

Resources