.htaccess -> index.php in web folder (url has to be web/) - php

I'm having problems setting up my .htaccess file. In my web folder (in the root of my project) I have index.php . Now I have to go to mydomain.com/web/ to see my index.php .
I've added a .htacces file in my /web folder but it isn't working. This is the content of my .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
What am I doing wrong?

You can have 2 .htaccess for this:
root .htaccess (a level above web):
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^((?!web/).*)$ web/$1 [NC,L]
/web/.htaccess:
RewriteEngine On
RewriteBase /web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php [L]

Have you tried RewriteBase ?
RewriteBase /web/
This post can be also helpful
How does RewriteBase work in .htaccess

Related

CakePhp3 Htaccess

I want to access image file in this folder by local.myproject/assets/logo.jpg
Note that /img/ folder is not in the URL
|-webroot
|-js
|-img
|-assets
|-logo.jpg
How can i configure this on my htaccess
currently my .httacess under webroot is like
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteRule ^assets/(.*)$ img/assets/$1 [R=301,L]
</IfModule>
And this is not working.
Try the following rule :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^assets(.*)$ /img/assets$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

htaccess/url rewrite with Silex, XAMPP, and multifolder structure

I've tried searching multiple previous threads on setting up url rewrite correctly for a Silex application on XAMPP, but still can't figure this issue out. Here is what I am trying to accomplish.
I am using XAMPP and here is the structure of my htdocs folder:
- xampp
- htdocs
- app1
- app2
- app3 <silex application>
.htaccess file (outside of web folder)
- web
index.php file
I can currently do http://localhost:50000/msk/web/cte. My question is how do I get rid of "web" from this (i.e. http://localhost:50000/msk/cte)
I feel like I'm missing something minor, but I can't figure it out.
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /msk/web/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
LoadModule rewrite_module modules/mod_rewrite.so is un-commented in my config.
I am not using virtual hosts either.
Thanks
Try this one
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
You can try :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /msk/web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteRule ^cte/url-word$ cte/redirect-page [L]
</IfModule>
use the following .htaccess in /msk directory:
Options +FollowSymLinks
IndexIgnore */*
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/(web)
# ------- browser looks for them on base url -------- ex: /images/logo.png
RewriteRule ^css/(.*)$ web/css/$1 [L]
RewriteRule ^js/(.*)$ web/js/$1 [L]
RewriteRule ^images/(.*)$ web/images/$1 [L]
RewriteRule (.*) /web/$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /web/index.php
</IfModule>
and use this .htaccess in your /msk/web directory
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
</IfModule>

Prevent .htaccess rules to the child folder

Here is my folder structure
www.mywebsite.com
www.mywebsite.com/app
www.mywebsite.com/app/firstproject
www.mywebsite.com/app/secondtproject
In the root directory i installed wordpress. It allows me to access the www.mywebsite.com/app but when i try to access the www.mywebsite.com/app it is always showing page not found i can guess that it is because of the .htaccess at the root folder.
Here is the .htaccess root folder
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I tried to override the .htaccess to the sub folders by having the below code in the .htaccess of the app folder but it shows the same page not found error.
RewriteRule ^app/ - [L]
How can i access the www.mywebsite.com/app/firstproject without that error ?
Remove app/.htaccess
Have this code in root .htaccess:
root .htaccess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(index\.php$|app/) - [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
# END WordPress
Write all rules in the root htaccess file.
add
RewriteRule ^app/firstproject$ - [L]
to prevent rewrite in this path.
For further rewrite within /firstproject, you need conditions and rules similar to web root
RewriteEngine On
RewriteBase /
RewriteRule ^app/firstproject$ - [L] #add longer path first
RewriteRule ^index.php$ - [L] #no need to escape \.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Slim Framework proper htaccess setup with wordpress

I want to make an api with slim. it would be on my "tools" subdomain in a directory called api.
http://tools.fifaguide.com/api
What should my .htaccess file look like?
Currently my .htaccess is located in my Wordpress directory (html -> .htaccess), and it looks like this:
<IfModule mod_rewrite.c>
//my part
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/api/index.php
RewriteRule ^api/(.*) http://tools.fifaguide.com/api/index.php [L]
//wordpress part
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
The problem with this is that when I try
http://tools.fifaguide.com/api/hello/steve
I imediately get redirected back to api/index.php instead of staying on /api/hello/steve and having the results shown.
Its seems like wordpress is making this happen, but how do I prevent it?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/api/ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ api/index.php [QSA,L]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

.htaccess in subfolder

The main site runs WordPress with .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I'm going to create an CodeIgniter app in subdirectory site.com/online/
If simply add CI .hta file in subfolder it wouldn't work. CI .htaccess:
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt|img|styles|js)
RewriteRule ^(.*)$ /index.php?/$1 [L]
Is it possible to combine two .htaccess files or to do something with .htaccess in CI subfolder?
Thank you.
UPD.
Thank you for answers, I've tried all variants, and eventually moved project to subdomain.
First thing, your .htaccess should be like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} !^GET\s/+online/ [NC]
RewriteRule . /index.php [L]
</IfModule>
#Then add this for CI handling in the same .htaccess
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !index\.php [NC]
RewriteRule ^online/(.*)$ online/index.php?/$1 [L,NC]
Then you can remove (or rename) .htaccess in the online subfolder.
Try this for the codeigniter .htaccess:
RewriteEngine on
RewriteBase /online
RewriteCond $1 !^(index\.php|robots\.txt|img|styles|js)
RewriteRule ^(.*)$ /index.php?/$1 [L]
Otherwise all requests to that subfolder would be redirected down to wordpress.
Are you setting AllowOverride? According to the docs you need to allow FileInfo overrides for mod_rewrite.

Categories