In an symfony project, is there any way to exclude a directory from being processed.
For example, I want to run a seperate php program in mysite.com/other_app
How can I exclude web/other_app folder from being processed by the symfony controller.
I've tried using
RewriteCond %{REQUEST_URI} !^/other_app/(.*)$
and
RewriteCond %{REQUEST_FILENAME} !-d
Symfony still processes the other_app which obviously isn't going to work properly. Any suggestions.Do I need to modify htaccess in other_app/.htaccess as well?
Also, let me add. When I access just the directory mysite.com/other_app I get the correct content. If I try and access anything below that, I get problems.
This works:
mysite.com/other_app
This does not:
mysite.com/other_app/page1
In the logs I get an error:
Action "other_app/page1" does not exist. Or something similar.
Ok. I figured it out. The .htaccess of the sub directory also needs to be modified.
In web/.htaccess use:
RewriteCond %{REQUEST_FILENAME} !-d
In the sub directory, web/other_app/.htaccess use:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /other_app/index.php [QSA,L]
This will work for wordpress and most any other php app that you want to run on a symfony site, but don't want to deal with trying to hack it into the framework.
Try adding:
RewriteCond %{REQUEST_FILENAME} !-d
Related
Currently, I'm trying to set up updates for passes that are added to the Wallet app on iOS.
One thing that is interesting is that having the url https://example.com/index.php/var1/var2 still works and index.php is still run. Is there a reason why this url format works?
.htaccess/mod_rewrite is the reason why it's working.
For example:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]
Having this rules inside a file named .htaccess in the root folder of your website, will make the path /var1/var2 available inside $_GET['path']
So I'm using the Flight PHP microframework (http://flightphp.com/) to do routing. My question is, how can I run the router from within a subdirectory? What I mean is, essentially, run it 'sandboxed' within a folder.
As in, a request to '/' just pulls the regular index.php file. But a request to '/flight/file' would load the URL using Flight.
I know you can't just dump it in a folder on the server and expect it to work because FlightPHP expects the URLs relative to the root.
Is there a way to run FlightPHP isolated in a directory with the rest of the website running regular PHP?
EDIT
I tried simply putting the .htaccess file into the subdirectory. This has the peculiar effect of causing the routes to still act as if they are from the root (e.g. /thing/otherthing/ when it should be /otherdirectory/thing/otherthing/ ) while simultaneously causing the 404 callback to not work. Not what I intended.
EDIT 2
Contents of .htaccess file, which are what is suggested by the Flightphp website:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
I know this is an old question but I've been doing something similar just by adding something along the lines of
RewriteBase /flight/
in the .htaccess file (before all of your rules) of the flight directory. Hope this helps someone else looking for the same thing. Example:
RewriteEngine On
RewriteBase /flight/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
Sorry for giving you an answer that is not going to help a lot. I'm running Flight (also sandboxing) on a subdirectory. I've created an .htaccess just with the defaults in the subdir and Flight is now regarding this as it's root.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
Did you check the content of the .htaccess on the higher levels, maybe there is something that is blocking you
Instead of working live on my site I've decided to try and work locally and install new version later on my live site.
So I'm working with Codeigniter and have the following struture.
/htdocs/kow(site)/kowmanager(cms)
When I load https:localhost/kow it loads the correct controller however for some reason its not reconizing that kowmanager is a sub directory of kow with its own application folder and it should be loading the default controller that is set in its routes file. When I load https://localhost.com/kow/kowmanager it loads a page that says index of /kow/kowmanager and then a link to the parent directory. Which isn't anything CI related.
Inside the kow directory this is my .htaccess file. Is this the problem?
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteEngine On
RewriteBase /kowmanager
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
I'm using xxamp.
You need an index.php-page for each application as stated by the manual.
So I think you should copy your index.php to indexManager.php and in it change the application folder.
$application_folder = "kowmanager";
About the rewrite I am not sure but I think it is in line with:
RewriteEngine On
RewriteBase /kowmanager
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ indexManager.php?/$1 [L]
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
are you using a .htaccess to remove index.php from urls ?
is /htdocs/kow the base directory of your project where CI is installed ?
you need to put kowmanagers in the controllers directory, and specify which controller to call, I'm not sure CI supports calling default controllers from directories unless you specify it in the routes.php config file.
Anyway, please give further information if you want a precise answer.
What is in kowmanager and why do you have two rewrites? If your directory structure is how I assume it is, you might get away with just removing the second kowmanager directive from your .htaccess file.
Which folder is codeigniter in? All you want to do is rewrite the url to remove index.php, but unless you're mapping the url to codeigniter's index.php, it will never be able to load controllers.
Apache has a lot of info on url rewrite. Its a lot of reading and the behavior is always pretty finicky, but maybe it will help you:
Otherwise, more info will help us help you. P.S. I'd also tag this with apache, as that is where the problem is, and you're more likely to get people who know a lot about apache to view your question.
I'm having trouble with a htaccess mod_rewrite preventing php files from being executed directly.
The site seems to be running on an MVC framework (not 100% sure on which one unfortunately) and requests are being sent through a router class. I have a subdirectory which I want to exclude from the routing and have its files be executed directly.
Here is my current htaccess file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rt=$1 [L,QSA]
I have tried excluding the subdirectory I want to execute directly with the following line but it made no difference:
RewriteCond %{REQUEST_URI} !^subdir/(.*)
Is there any way I can execute the php files in subdir directly? Any help would be much appreciated, thanks.
Have you tried with RewriteCond %{REQUEST_URI} !^/subdir/ ? The REQUEST_URI may start with a /.
RewriteCond %{REQUEST_FILENAME} !-f
This line allows you to execute files directly. If you are getting error 500, check your scripts for fatal errors / uncaught exceptions
Every single time a user registers on my site I would like them to have their own subdirectory with their registered "username". Every user subdirectory will have the same "index.php" file which will do something.
For example: "/users/username1/" and "/users/username2/"
If some one wants to access the subdirectory they would simple go to:
"www.example.com/users/username1/" or "www.example.com/users/username2/"
The easy and messy solution would be to simply create a subdirectory for every user and place the same "index.php" file in every directory. But to me this is only going to crowd my server space and make my directories large.
I wanted to know if all this can be done using .htaccess? Can I create one "index.php" and one ".htaccess" file and place them both in my "/users/" directory? What would be the actual code that I would have to place in my .htaccess file??
If you have a better way of doing this please let me know. I am using Apache and PHP as my working environment.
Thank you
Well, for example, you could do it all with one htaccess like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
What it does:
switches on rewrite engine
checks if a requested file exists
checks if a requested directory exists
if NOT, it redirects request to your main index.php
Basically that means if you enter url such as yourdomain.com/users/ivan/, you request will be redirected to:
index.php?url=/users/ivan
then you $_GET['url'] in your index.php and split it into pieces.
That's just an example, there other mod_rewrite methods to do this.
Make it virtual. There are no subdirectories, you can use mod_rewrite to simulate that.
With mod_rewrite you can make /users/username1 lead to /users.php?user=username1 for instance. Everything is transparent for the client, he wont notice what is really happening.
By using something like this:
RewriteEngine On
RewriteRule ^([\-_0-9A-Za-z]+)$ index.php?a=$1 [L]
You can customize RewriteRule as much as you want.
You can essentially type in any directory you want, and it will be redirected to your index.php page.
If you want to make sure the existing directories are not redirected, do this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([\-_0-9A-Za-z]+)$ index.php?a=$1 [L]
If you want to limit the scope, so only a subdirectory of user/ is redirected (similar to Stack Overflow), simply add in 'user' to the start of the rule:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^user/([\-_0-9A-Za-z]+)$ index.php?a=$1 [L]
And finally, if you want to have an individual file handle all user requests seperate from your actual index.php page:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^user/([\-_0-9A-Za-z]+)$ users.php?a=$1 [L]
This is a very similar setup I use to distribute CSS files.
Note: The Directory will be contained is $_GET['a']