i have .htaccess file which includes below code.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L]
RewriteRule ^imagefactory/(.*)$ imagefactory/index.php?q=$1 [QSA]
i want .htaccess file which fulfill below requirements.
if
1) url/admin then go to the admin folder and choose it's .htaccess file
2) url/imagefactory then go to the imagefactory folder and choose it's file called index.php
3) url/ then it choose root directory's index.php file
Try This
RewriteEngine on
RewriteRule ^imagefactory/(.*)$ imagefactory/index.php?q=$1 [QSA]
RewriteRule ^admin/.$ - [PT]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1
You should place the last rule 1 position up. This rule RewriteRule ^(.*)$ index.php?q=$1 [L] will match anything, and the [L] attribute there means not other rules will be evaluated when it matches. If you reorder it like below it should work.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^imagefactory/(.*)$ imagefactory/index.php?q=$1 [QSA]
RewriteRule ^(.*)$ index.php?q=$1
The .htaccess file is read in sequence. The RewriteCond are only meant for one rule.
Therefore all you need is:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^imagefactory/(.*)$ imagefactory/index.php?q=$1 [QSA, L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/admin/(.*)$
RewriteRule ^(.*)$ index.php?q=$1 [QSA, L]
The second block is a catch all so that if its not from directory admin, use the default root index.php.
Related
I'm trying to remove the proxy.php file and the parameter passed to it. This is what it looks like currently.
http://localhost/stuff/proxy.php?parameter=folder01/some.file
This is the way I would like it to look.
http://localhost/stuff/folder01/some.file
For my htaccess file, I have tried the following but they do not work.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /proxy.php?parameter=$1 [L]
And this
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/?$ /proxy.php?parameter=$1 [L,QSA]
Any ideas?
Try it in root dir or put this in stuff directory and remove RewriteBase line.
RewriteEngine on
RewriteBase /stuff/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ proxy.php?parameter=$1 [L]
this is my .htaccess
RewriteEngine On
RewriteCond $1 !^(index\.php|public)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(acp|acp/)$ /acp/home.html [L,R=301]
RewriteRule ^(.*).html$ index.php/$1 [QSA,L]
But when i upload html file into root folder (example: ads.html) and run http://domain.com/ads.html it's not work, how to fix it
Conditions only work for the rule they appear before. Your conditions work for the rule that rewrites acp to acp/home.html. You want to move the conditions directly before the second rule. You would end up with:
RewriteEngine On
RewriteRule ^(acp|acp/)$ /acp/home.html [L,R=301]
RewriteCond $1 !^(index\.php|public)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*).html$ index.php/$1 [QSA,L]
I'm trying to redirect all requests to ./index.php?site=$1 while I only want to use the part behind the last slash.
So I want www.mydomain.com/firstpage to become www.mydomain.com/index.php?site=firstpage and www.mydomain.com/subfolder/anotherpage to become www.mydomain.com/subfolder/index.php?site=anotherpage
But right now www.mydomain.com/subfolder/anotherpage becomes
www.mydomain.com/index.php?site=subfolder/anotherpage
This is what I've got:
RewriteEngine on
Options +SymlinksIfOwnerMatch
RewriteBase /
RewriteCond %{HTTP_HOST} ^mydomain.com$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?site=$1 [L]
What could I do to redirect only the part after the last slash?
Thank you so much!
SOLUTION:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*/)?([^/]+)$ $1index.php?site=$2 [L]
Found this other, on my opinion more elegant solution. By this, the number of subfolders is irrelevant.
SOLUTION:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*/)?([^/]+)$ $1index.php?site=$2 [L]
Finally figured out the answer myself.
At first I tried putting more RewriteRules under the same RewriteCond-lines gave me server errors. So I duplicated the RewriteCond-lines for the subdirectories:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)$ $1/index.php?site=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?site=$1 [L]
i have this problem:
I have an .htaccess file witch rewrites all my url's to index.php
i have an exception for a few folders.
THis words fine, but when a file doesn't exist in one of this folders he still does the rewrite. But he may not doe that.
How can i fix this problem?
My code :
RewriteEngine On
RewriteRule ^(templates|images)/ - [L]
RewriteRule ^(favicon\.ico) - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]
Try this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} !^/(templates|images|favicon\.ico) [NC]
RewriteRule .* index.php [L,NC]
I have a simple piece of ModRewrite that channels everything to index.php if it's not an existing file or directory.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
Now I want to add a exception when the domain contains certain strings, but I don't know how to to add this. I was thinking of adding the following.
RewriteCond %{HTTP_HOST} ^(aanmelding|keyclamps|probouw)
RewriteRule ^(.*)$ /project.php/$1 [L]
UPDATE, I found a partial solution
If I put it like this:
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# If not an old project
RewriteCond %{HTTP_HOST} !^(aanmelding|keyclamps|probouw)
# forward it to index.php
RewriteRule ^(.*)$ /index.php/$1 [L]
# Else
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# forward it to project.php
RewriteRule ^(.*)$ /project.php/$1 [L]
It works, but with a bug. Because index.php exists, the second part of the conditional still goes to index.php instead of project.php when a plain domain is called like http://probouw.localhost/
Any ideas?
For anyone that might need this, the solution was:
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# If not an old project
RewriteCond %{HTTP_HOST} !^(aanmelding|keyclamps|probouw)
# forward it to index.php
RewriteRule ^(.*)$ /index.php/$1 [L]
# Else
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteCond %{REQUEST_URI} =/
# forward it to project.php
RewriteRule ^(.*)$ /project.php/$1 [L]
Perhaps using OR would help (NC=NotCase sensitive by the way)?
RewriteCond %{HTTP_HOST} ^.*aanmelding.*$ [NC,OR]
RewriteCond %{HTTP_HOST} ^.*keyclamps.*$ [NC,OR]
RewriteCond %{HTTP_HOST} ^.*probouw.*$ [NC]
In reference to your partial solution, if you change the last part does this work?
# forward it to project.php
RewriteRule ^/?$ /project.php [L]
RewriteRule ^(.*?)$ /project.php/$1 [L]