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]
Related
Here's my current code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ /go/redirect.php?slug=$1 [L]
This file is located at http://example.com/go/.htaccess
It is working correctly when people visit this link:
http://example.com/go/test
But not when it has a trailing slash like this:
http://example.com/go/test/
When the trailing slash exists, they are being redirected here for some reason:
http://example.com/test
How can I make this work with and without trailing slashes at the end of the URL?
Try with below,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /go/redirect.php?slug=$1 [L]
I'm having some trouble with my .htaccess. First, I've created a subfolder and then I've made that subfolder as root like this:
RewriteEngine On
RewriteRule ^app/(.*)$ $1
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
So far so good, problem is when I request something like:
mysite.com/subfolder/page
Or hit refresh it takes me to the main domain.
Have this code in app/.htaccess:
RewriteEngine On
RewriteRule ^index\.php$ - [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
I want to change page url with .htaccess my url is 'page.com/web/' and I want to have just page.com. Could you give me htacces code. for example
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /?$1 [L]
Try this :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ web/$1 [NC,L]
Sorry that i'm new on htaccess and have a issue now.
I was able be redirect from domain.com/admin to www.domain.com/admin
But failed with domain.com/test which bring me back to www.domain.com, and it's fine if i go in with fullname www.domain.com/test
Both /admin and /test are valid subdirectory, only different is /admin doesn't have htaccess file but /test do have
this is my home htaccess:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ page_process.php
And this is subdirectory /test htaccess
RewriteEngine on
RewriteBase /test/
RewriteOptions inherit
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /test/page_process.php
Would appreciate any help! Thanks!
Try this code for the htaccess in the root directory :
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /page_process.php
And this code for the htaccess in the test directory :
RewriteEngine on
RewriteBase /test/
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ page_process.php
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.