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]
Related
I want to rewrite my url from http://xyz.edu/profile.php?name=gavin to http://xyz.edu/gavin.html
Sample code:
RewriteRule ^profile\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ profile.php?compname=$1 [L]
Well it's about the same rules you already have. Try this and let me know how it works for you.
RewriteEngine On
RewriteRule ^profile\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.html$ profile.php?compname=$1 [L]
I have a directory structure for my apis as:
api/
cameras/
index.php
...
.htaccess
bar/
set/
index.php
scan/
index.php
retrieve/
index.php
list/
index.php
Before I added the bar folder I had this working with my .htaccess folder
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php [L]
I then added this to make it work.
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule bar/set/(.*) bar/set/index.php [L]
RewriteRule bar/scan/(.*) bar/scan/index.php [L]
RewriteRule bar/list/(.*) bar/list/index.php [L]
RewriteRule bar/retrieve/(.*) bar/retrieve/index.php [L]
RewriteRule (.*) index.php [L]
They all work except the first one in the list set. What have I done wrong?
I think the order of your conditions might be causing an issue. Without seeing the URL's you are using I would have to assume. However RewriteCond only applies to the rule directly following it. You put the new rules between the conditions and your original rule. Change the order and try it this way and see how it works.
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
RewriteRule ^bar/set/(.*)$ bar/set/index.php [L]
RewriteRule ^bar/scan/(.*)$ bar/scan/index.php [L]
RewriteRule ^bar/list/(.*)$ bar/list/index.php [L]
RewriteRule ^bar/retrieve/(.*)$ bar/retrieve/index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php [L]
RewriteCond only gets applied to next RewriteRule. Try this code instead:
DirectoryIndex index.php
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%1]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(bar)/(scan|set|scan|retrieve)/(.*)$ $1/$2/index.php [L,NC]
RewriteRule . index.php [L]
I got a simple Wordpress .htaccess:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
What i am searching for is how to make the .htaccess be aware in which environment it runs, to change the RewriteBase and RewriteRule accordingly.
Something like (dummy)
if HTTP_HOST == "192.168.0.1" RewriteBase /localfolder, RewriteRule . /local/index.php [L]
else (for all other domains assume online) RewriteBase /, RewriteRule . /index.php [L]
Is there a way to achieve this?
I tried something like
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP_HOST} =192.168.0.100
RewriteBase /local/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /local/index.php [L]
but don't get it to work. always the first rules are apllied
UPD:
This seems the perfect solution for offline and online:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
# END WordPress
This seems the perfect solution for offline and online:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
# END WordPress
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 .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.