Silex and htaccess to /web - php

I m actually creating a simple application using Silex and I m having some problems.
Actually, I run on an Apache 2 server and I have the fallback /index.php set in my ht access at the root of my application.
In fact, I actually have to get these kind of routes :
http://127.0.0.1/appname/web/index.php/route
And I need something like
http://127.0.0.1/route
I absolutely don't know how to proceed...
Can you help me a bit ?

Modify your .htaccess to change your root directory and to replace the index.php.
RewriteEngine On
RewriteBase /appname/web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ %2index.php [QSA]

Related

How should I configure redirects for multisite Codeigniter app?

I have multiple codeigniter sites setup like so:
/CI_Site1
/CI_site1/CI_Site2
/CI_site1/CI_Site3
Right now to use my the second and and third site I have to do it like so:
mydomain.com/CI_Site2/index.php/controller/function
If I don't put the index.php then it throws up a 404 in the root site(AKA CI_Site1).
How should I configure htaccess or apache site conf or CI config files such that I don't have to add index.php?
I think the first step should be to configure the routes in CI_site1 to not process requests for the other 2 but I don't know how. Here is hoping a Codeigniter pro can help me.
Thanks in advance.
EDIT: I know how to remove index.php from URLs with htaccess. But that is not the issue here. How do I prevent CI_site1 from processing requests that are for CI_site2 and CI_site3?
Just add below code in file and save it as .htaccess then upload it to Project folder
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]
Make sure your server mod_rewrite is on.
Did you try using routes?
$route['CI_Site1'] = '/CI_Site1';
$route['CI_Site2'] = '/CI_site1/CI_Site2';
$route['CI_Site3'] = '/CI_site1/CI_Site3';
I realized that no extra configuration was required. It is sufficient to use .htaccess to remove index.php. My issue was that apache was blocking .htaccess files in its default configuration. Editing apache2.conf to allow processing of htaccess files resolved my issue.

htaccess for domain and subdomain with laravel

I'm trying to figure out how to set up a domain and subdomain to work on a shared hosting account. It is a Laravel 5.1 application.
My access file is
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteRule ^ index.php [L]
I just purchased another domain and added it on, but I get a 500 error. I renamed the access file and then it worked. So it has something to do with the access file. Essentially I want two separate domains with and I'm wanting two separate laravel applications, one for each.
I'm not familiar with atacceess.
Maybe, you get a redirect loop, because the rule isn't protected by a condition. Although the default htaccess of Laravel should already contain them.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
Olaf Dietsche's answer does work for me.
Here is another thing I came upon a website that also worked just before I saw his post. I guess I was reading that this would send a 404 to that directory.
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteRule ^ index.php [L]
RewriteCond %{HTTP_HOST} ^(www.)?main-topdomain.com$ [NC]
RewriteCond %{REQUEST_URI} ^/subdomain-folder/(.*)$
RewriteRule ^(.*)$ - [L,R=404]
So along with this comes another question if anyone is in my boat. I have my subdirectory inside of my root directory.***
dlaugh.com/public_html
laravel folders and access**
inluding
app
bootstrap
config
database
etc...
but also I have my sub folder
app
bootstrap
config
database
etc...
**mysubdomain in that folder**
Is it better practice to put
-main_domain_folder and
-subdomain_folder
in public_html
and then the
/app
/config
/database
would be in the main_domain_folder rather than passing the subdomain through the main domain?

Relative path to sub-directory in PHP and Apache's htaccess file

I am working on my own PHP Framework. I am currently developing it on localhost and everything related to project is in subfolder called RuddyPhpFramework, so the path look like this:
localhost/RuddyPhpFramework/
In that folder, I do have index.php, the init point of whole Framework. I am currently working on my own router, but I have a two problems. First, in Apache's htaccess file a have this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) RuddyPhpFramework/index.php [L]
So whenever someone acces a page like this:
localhost/RuddyPhpFramework/something/smtelse/
The index.php will init the application and echo a path for me, which is:
[path] => /RuddyPhpFramework/something/smtelse/
But that is not excatly what I want. What I want is to get a relative path to subfolder (I don't know if I am explaining this correctly), for example:
[path] => /something/smtelse/
And another problem is that I want to setup the htacces so the last line would look something like this:
RewriteRule (.*) index.php [L]
So it will go for the index.php in the folder where is the htaccess file (/RuddyPhpFramework/index.php) and not /index.php, without specifying the foler, because if someone else will be using the framework, he might have it in a folder with different name.
first please stop we have enouth frameworks already. Now regarding your question. Your project is in localhost/RuddyPhpFramework so htaccess read url from first / so he skips localhost because it's domain and taiks uri witch starts from /
so you project setup is incorrect. what you could try not shure 100%:
RewriteEngine On
RewriteBase /RuddyPhpFramework/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) index.php [L]
please try it. and say did it helped.

routing index.php with htaccess

I am running wamp on win7 just in case. I am trying to route all requests through a route.php to get clean URLs. Below is my htaccess
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !(auth|folder2) [NC]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*) ./route.php?path=$1 [L]
As you can see the rule should apply to all files, and it did when I ran it on my old wamp installation. Now after copying the files to a new system, for some reason, the rule seems to work for all links except index.php. So if I try http://localhost/proj, I get no routing in the new system. Any ideas?
And before anyone asks, yes rewrite_module is on, and the htaccess is being read and executed cause it works for all other links like http://localhost/proj/users and also because if I try putting garbage values in the htaccess it throws a nice 'internal server error'.
I'm guessing you have an index.php in that folder, and this condition:
RewriteCond %{SCRIPT_FILENAME} !-f
...tells apache to perform the rewrite only if the file does not exist.
I would suggest or renaming the file, as you'll need that condition to route static assets like images, scripts, etc.
If there is no index.php (or index.htm[l]) in that folder, just define route.php as the default file in that directory. In your .htaccess:
DirectoryIndex route.php index.php index.html index.htm
(Be aware that this will also apply to any sub-directories as well)

PHP MVC & .htaccess 301 Redirect

I am restructuring a website to a MVC framework and am in the process of moving everything from root the root directory into an organized file structure. So now instead of going to domian.org/homeloans.php, the users will need to do domain.org/loans/homeloans. Here is the .htaccess file I use to direct website traffic.
RewriteEngine on
DirectorySlash on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rt=$1 [L,QSA]
Shouldn't this be as simple as adding:
Redirect 301 /homeloans.php https://domain.org/loans/homeloans
after turning the rewrite engine on? However, when I do this, I get this in my address bar along with a 404: https://domain.org/loans/homeloans?rt=homeloans.php
Please advise.
The problem seems to be not with the rewrite, but with the ability of your new MVC site to handle this URL. It looks like it can handle:
/loans/homeloans
but not
/loans/homeloans?rt=homeloans.php
Try accessing both directly; if the latter doesn't work but the former doesn't, then you know the issue is with the routing configuration of your MVC application.

Categories