Imagine yourself a simple symfony install:
symfony new testsite
Now imagine this is inside the webroot of an apache server. Of course this won't work since the symfony webroot is in the /web/ folder.
So you make a simple rewriterule and drop it in a htaccess in the symfony folder:
RewriteEngine On
RewriteRule ^(.*)$ web/$1 [QSA,L]
And this works. Hooray! So you try out the "Create your first page in symfony" guide and lo and behold your controller's 404ing!
So it seems like symfony is cutting off 3 characters from the start of the path. A bit of debugging shows it's getting the base url from the $_SERVER['SCRIPT_NAME'] which is the cause of the problem, since this doesn't change when you rewrite the url.
Is there a proper way to fix this or do I just have to redefine SCRIPT_NAME manually in my app.php?
if you comments are correct, then the URL you should be using is:
symfony-test.local/web/app_dev.php/lucky/number
You should specify the DocumentRoot as the web/ folder! That is normally what is done. Read this for more details:
http://symfony.com/doc/current/setup/web_server_configuration.html
Related
I've been trying to change my CodeIgniter file structure to make it safer and cleaner but I can't get it to work. I want to separate the application/system and the public files that are going to be visible to users.
- application
- system
- public
It works but I have to enter
example.com/public/index.php or example.com/public/controller
I want to be able to just type the base URL like example.com/controller.
How can I do it?
For CodeIgniter 3.x, the correct way to approach this (at this point in 2018 and after) is as follows:
Make a public folder in your root folder
MOVE your index.php file into this folder (to prevent ambiguity)
inside the moved index.php file, change the following:
change $system_path to ../system
change $application_folder to ../application
Now, we need an .htaccess file, but CI 3.x doesn't have a .htaccess file by default, soo.. how about stealing it from CI 4.x which has it by default? You can find it here:
https://github.com/bcit-ci/CodeIgniter4/blob/develop/public/.htaccess
I recommend you NOT include the line SetEnv CI_ENVIRONMENT development - instead, define this in your apache or NGinx .conf file so the .htaccess file can work anywhere.
Finally, you'll meed to update your .conf file so that DOCUMENT_ROOT is set to the subfolder named public (or whatever you chose to name it). Then restart Apache/Nginx.
That should give you the same results, and be much more secure.
-- UPDATE --
I found that I had problems with the .htaccess file from CI 4, however suspect it's my system that's the problem. This simple version did work however:
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|images|js|css|uploads|favicon.png)
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^(.*)$ ./index.php/$1 [L]
As per the CodeIgniter Installation Instructions...
/var/application/
/var/system/
/var/www/index.php
For the best security, both the system and any application folders should be placed above web root so that they are not directly accessible via a browser. By default, .htaccess files are included in each folder to help prevent direct access, but it is best to remove them from public access entirely in case the web server configuration changes or doesn’t abide by the .htaccess.
I am trying to run laravel4 on a service that cannot use Apache or nginx.
everything is good till I wanted to use Routes on my project.
I've tried using /index.php/... on the URL but could not make this work.
is there any way to force laravel not to use .htaccess file or any ways to use raw PHP routing?
Try setting the "application.url" option in one of configuration files, probably in app/config/application.php or application/config/application.php:
https://github.com/laravel/laravel/blob/4cb904f44d24f856ec9c1040d2198ed8f009723b/application/config/application.php
Set it to http://127.0.0.1:54007/index.php. Now when laravel creates url it will use this as a root and the final urls should be like http://127.0.0.1:54007/index.php/account/signin.
Also you need to modify PHP Desktop settings so that it uses a fixed port. Edit settings.json file and set it like this:
"web_server": {
"listen_on": ["127.0.0.1", 54007],
In laravel's .htaccess I've found this:
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
So it should work fine to add "/index.php" to root url, because this is what apache's mod_rewrite does.
If something doesn't work, take a look at some other files named "url.php", "uri.php".
Let us know if that works.
EDIT.
You may also try setting root url to "index.php", without the "http://". This way it wouldn't be required to set a fixed web server port.
UPDATE
There was a bug in Mongoose web server in PHP Desktop, that prevented urls like "index.php/company/5" from working properly. See the __fix_mongoose_env_variables() php function in Issue 137 that fixes it:
https://code.google.com/p/phpdesktop/issues/detail?id=137
I have been using code igniter as a subdirectory of a site and have several instances of if on one server. Each instance is considered a separate application, but all under the same domain name. I am looking to enable a slightly different URL structure though and have turned to mod_rewrite to help me out.
The page is reachable at http://localhost/test but I want to rewrite that URL to appear as http://localhost/en-US/test.
The problem is I keep getting a code igniter (CI) 404. I can confirm the mod_rewrite is reaching the CI index.php, but CI is failing to deliver the correct page. Here's and example setup:
1) Download a new instance of CI and place it in a subdirectory in the site root. Name the CI folder "test". It should be reachable now on a local server at http://localhost/test and you should see the default welcome view.
2) Create a .htaccess file in the server's root web directory. DO NOT place it in the CI "test" directory. Add the following lines to it.
RewriteEngine On
RewriteBase /
RewriteRule ^en-US/test/?$ test/index.php [NC,L]
From my understanding of mod_rewrite, this should allow the URL http://localhost/en-US/test to render what is located at http://localhost/test. It doesn't though. I just get the CI version of a 404. I need help figuring out how to resolve this.
Hmm your question made me install CodeIgnoter and read its routing :)
Anyway have your DocumentRoot/.htaccess like this:
RewriteEngine On
RewriteBase /
RewriteRule ^en-US/(test)/(.*)$ $1/$2 [NC,L]
Then replace this line in your /test/application/config/config.php`:
$config['uri_protocol'] = 'PATH_INFO';
It is by default set to:
$config['uri_protocol'] = 'AUTO';
After this you can open this URL: http://domain.comen-US/test/ to load CI home page in /test/ dir.
You should check out routing. Place this statement in your config/routes.php file AFTER the reserved routs.
$route['test'] = "en-US/test";
You can forget about htaccess when you have Codeigniter (most of the times).
My Project is done in Symfony 1.4 framework (PHP). Its configured on my machine and I can access the application as http://localhost:8082.
All my urls are like
xhttpx://localhost:8082/login
xhttpx://localhost:8082/logout
xhttpx://localhost:8082/new/item
xhttpx://localhost:8082/item/edit/id/34 etc.
Now i want to change all my urls to
xhttpx://localhost:8082/pink/login
xhttpx://localhost:8082/pink/logout
xhttpx://localhost:8082/pink/new/item
xhttpx://localhost:8082/pink/item/edit/id/34 etc.
i.e. append pink after the base url (http://localhost:8087).
I want to achieve this without modifying the Symfony 1.4 files (e.g. routing.yml etc).
I guess we can achieve this by modifying the httpd.conf and by writing appropriate rewrite rule.
Note: please read xhttpx as http, as stackoverflow was not allowing me to post hyperlinks.
Please help.
Create a .htaccess file in the root, containing this:
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://localhost:8082/pink/$1 [R=301,L]
This tells Apache to route all traffic in the folder that the .htaccess is in to /pink/.
My backend URLs look like this:
mysite.com/backend.php/blog
I'd like to change it to:
mysite.com/backend/blog
Technically this isn't limited to admin apps, as Symfony grants every application two front controller scripts. But I hate having the script name in URLs and as such I'd like to change it. Is this possible?
Thanks in advance.
Edit
#codecowboy - I did resolve this by creating a 'backend' directory in the web directory. I then copied over the .htaccess file symfony puts in web, and I moved the backend.php and backend_dev.php front controllers to /backend and renamed them index.php and index_dev.php. Then within each front controller I tell PHP to look one directory further up for the project config class. I've been doing this for a while now and it serves my needs perfectly. I actually wrapped this all up in a task so that setting up a new admin app is a 1 step processs.
You can add
#I'm no regular expression expert or mod_rewrite expert, this line probably has some bugs
RewriteRule ^backend(.*)$ backend.php [QSA,L]
to your .htaccess file right before
RewriteRule ^(.*)$ index.php [QSA,L]
and that solves 1/2 of your problem. Anything sent to yoursite.com/backend/xxx will be routed through backend.php. The other problem you get is with internal symfony routing. It will interpret yoursite.com/backend/xxx as a request for module "backend" and action "xxx". I'm sure it's not too hard to solve. Good Luck!