Htaccess if doesn't exists, doesn't work - .htaccess

I don't have much experience with htaccess. But I have this script:
Options +FollowSymLinks
ErrorDocument 404 /index.php
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)$ index.php?doel_url=$1 [L,QSA]
But if there exists a file, he just listen to this rule.
Help!

website.nl/categorie is not a file and is not a directory.
if you need categorie to go to the file you will need to make sure it has a file extension (in your case .php) so it should be website.nl/categorie.php to avoid being redirected to the index.php page

Options -MultiViews should fix that.

Related

Infinite amount of rediretcs with .htaccess in subdirectory

I'm trying to get a webpage running which might not get any support anymore, so I have to fix this on my own. So in the root directory, I have this .htaccess file:
RewriteEngine on
RewriteBase /
RewriteRule ^(.*) resources/$1 [L]
So all the content gets redirected to the resources/ folder. Now this kinda works, as the frontpage shows all the static content (CSS, JS, Images). But when I try to open mydomain.com/admin, I'll get an HTTP 500. The logfile says
AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
The .htaccess file in the sub-dir has this content:
Options -MultiViews
RewriteEngine On
Options -Indexes
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?param=$1 [QSA,L]
For my basic Apache knowledge this does seems quite right; but is it, or do I have change Apache settings? (The VPS is a kind of PaaS-thing, so I can access/change some things)
Thank you.
Have your root htaccess rule file in following way(you need to put a condition for a check before rewriting).
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/resources [NC]
RewriteRule ^(.*)$ resources/$1 [L]
Then for your sub directory level htaccess file try following:
Options -MultiViews
RewriteEngine On
Options -Indexes
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?param=$1 [QSA,L]
Also in case you want to apply same rules which you have in your root directory to sub-directories then add RewriteOptions InheritBefore before RewriteEngine ON in your sub directory level htaccess file.

RewriteCond %{REQUEST_FILENAME} !-d not working

I have seen several other threads about this but for some reason in my specific case the solutions are not working.
Here is the .htaccess
DirectoryIndex index.php index.html index.htm
Options +FollowSymLinks -Multiviews -Indexes
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?page=$1
The desired effect is that index.php will load what ever page is requested in the GET (/events-diary = index.php?page=events-diary) & that works fine.
However I have some REAL directories which need to be accessible for example /admin/
The above .htaccess works perfectly fine as desired on my home computer MAMP, it works perfectly fine on my Amazon Micro, it will not work on the deployment server ipage.com
When you enter /admin it will redirect to the root index. When you type /admin/index.php it works, but you have to specify the index.php
I cant figure out when it seems to be ignoring the !-d
UPDATE:
index.php contains the following PHP
if(!isset($_GET['page'])){
header("Location: home");
exit;
}
$line=page_content($_GET['page']);
note that this functions fine on the other 2 servers, i dont see why it would behave differently on the 3rd.
Use:
Options +FollowSymLinks -MultiViews -Indexes
With -MultiViews with uppercase V.
For Apache, in some cases upper/lower case are very important
Here is a different set of rewrite rules that might work for you:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?page=$1 [NC,L]
Are you trying to route things to /admin/index.php? If so, you could create a copy of your .htaccess, upload it to the /admin directory and set the RewriteBase to /admin.
or, if you wanted to turn the rewrite engine off in your /admin directory, you could create an .htacess file that contains:
RewriteEngine off
Difficult to post these suggestions in comment so resorting to an answer.
Try this rule:
ErrorDocument 404 default
ErrorDocument 403 default
DirectorySlash On
DirectoryIndex index.php index.html index.htm
Options +FollowSymLinks -Multiviews -Indexes
RewriteEngine on
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}/$1 !-f
RewriteCond %{DOCUMENT_ROOT}/$1/ !-d
RewriteRule ^([\w-]+)/?$ index.php?page=$1 [L,QSA]

Rewriting subfolders using nice url

When I go to http://www.example.com/youtube/detail/abvcde in my browser, I want to internally rewrite the url to http://www.example.com/youtube/detail.php?id=abvcde. I tried to do this with the following .htaccess, but it gives a 404 error.
Currently my .htaccess looks like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L]
Put the following code in a htaccess file in server root directory:
RewriteEngine On
RewriteRule ^youtube/detail/(.+)$ youtube/detail.php?id=$1 [L]
You can put this code in your /youtube/.htaccess
Options -MultiViews
RewriteEngine On
RewriteBase /youtube/
RewriteRule ^detail/([^/]+)$ detail.php?id=$1 [L]

Exclude folders when redirect with htaccess

I have a question.
I want to redirect domain.com/var to domain.com/id=var
I can do that, but when users write a var like my folders, the htaccess redirect to the folder first :/
This is my actual htaccess
Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^([a-zA-Z0-9-+/]+)$ index.php?id=$1 [L]
RewriteRule ^([a-zA-Z0-9-+/]+)/$ index.php?id=$1 [L]
But when the user write for example css, the htacces redirecto to domain.com/css/?id=css
And the second problem is if the user put / after the var, example domain.com/var/
How can I change that? Thx 4 all!!
You need to skip files/directories from rewriting:
Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9+/-]+)/?$ index.php?id=$1 [L,QSA]

htaccess only in root folder

I was looking for an answer, but didn't find it. I have .htaccess in root file which redirect /loremipsum/ to index.php?url=loremipsum, but, it also wants to work in subdirectories. I have a lot of them, so putting .htaccess file in everyone would be painful. Is there any way to make it working only in root folder?
if you add this rules it will only work on files and folders that didnt exist
Options -MultiViews +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ index.php?url=$1 [L]
To make your redirect rule work only in root dir use this negative lokahead based code:
Options -MultiViews +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)(?!/.*)$ index.php?url=$1 [L]

Resources