Zend Framework with phpBB: URL problem - php

I am using zend framework with Apache sever on Ubuntu. When I try my site on localhost, I use following url
for example:
http://test.dev/authentication/login
http://test.dev/student/profile
Where 'authentication' refers to AuthenticationController and 'login' refers to loginAction.
'student' refers to StudentController and 'profile' refers to profileAction.
Question: Now I want to use phpBB forum with my site. I had to use the following URL to start phpBB forum with my website.
http://localhost/test/forum/
Where 'test' is my main project(website) directory. I want to use following URL for phpBB forum.
http://test.dev/forum/
How to configure my project to open phpBB forum using above URL? Should I create a controller?
Thanks

I guess you are using apache mod_rewrite with your ZF application.
The simplest solution is to place a new .htaccess file inside the forum/ directory and turn off the rewrite engine
RewriteEngine Off
This works because Apache first look for the .htaccess file in the requested directory, if it does not find one, he looks in the parents folder and so on until it reaches the public directory. When you request /forum/ he finds the .htaccess file there and turns off the RewriteEngine.

After some time I have found my answer. I just placed my 'forum' folder in 'public' folder and it is working for me without changing my .htaccess file.
Here is my settings:
My directory structure is now like this:
/var/www/test/public/index.php
/var/www/test/public/.htaccess
/var/www/test/public/forum
My httpd.conf entry is like this:
<VirtualHost 127.0.0.1>
ServerName test.dev
DocumentRoot 'C:\wamp\www\test\public'
</VirtualHost>
My .htaccess file is like this(it controls both folder and controller/action URLs):
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Last line in above .htaccess file allow me to use my URL without index.php in URL.
After above setting I am able to use following URLs correctly:
http://test.dev/authentication/login
http://test.dev/student/profile
http://test.dev/forum/
In above URLs 'authentication' and 'student' are controllers. 'login' and 'profile' are actions and forum is a directory
Comments are welcome.
Thanks

This will work as well:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(js|ico|gif|jpg|png|css)$ /index.php
If you place phpBB in the public folder the webserver will be able to see it and the 2nd two lines of this code will exclude "real files" and "real folders" from the rewrite which is what you want for the forum folder. Obviously the last time, pushes all framework traffic to the index.php file.

Related

htaccess - Redirect parent folder PHP script

I have this web api project which is developed by other company. The file structure is:
/project
---/app
---/ApiEndpoint.php
---/public
---/index.php
The DocumentRoot is pointing to /project/public. The index.php is working (http://myapi.com/), however when I try to browse into the api endpoint http://myapi.com/api/endpoint I got 404 error.
How do I configure the .htaccess to rewrite this condition?
/project/public/.htaccess config
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*)$ /index.php?path=$1 [NC,L,QSA]
</IfModule>
The current configuration is there to make sure every request go to index.php (that is probably dispatching requests in some way) except for the files that actually are in the public directory (probably needed for static files like images, and such).
If you wrote a php yourself to be directly called by http://myapi.com/api/endpoint, you should put it in /project/app/public/api/endpoint/index.php.
BUT I suspect you should study that application more and understand the current dispatching method, before doing that.

Remove public_html from url through htaccess

I have a legacy project on a server where the actual framework is in a folder above the public_html folder. So the directory structure is like this:
domainname.com
app/
framework/
public_html/
index.php
Now I want to place this on our own server. This is an application created by the hosting company. The root folder is default. So now my directory structure is like this:
default/
app/
framework/
public_html/
index.php
Now he's pointing to the default folder instead of the public_html folder. That's the only difference with the old version. So I've added a .htaccess file to the root folder default. The content of this file is:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /public_html/$1 [QSA,L]
</IfModule>
In my public_html folder I have a .htaccess file like this:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule . index.php [QSA,NS]
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule . /index.php [L,QSA,NS]
So when I go to my website it works. But when I click on a link I get: http://domainname.com/public_html/theclickedpage/.
But I don't want the public_html in my url. How can I fix this?
You may want to search for a way to make a virtual host. I know some of my webhost let me configure the vhost through my admin page. It will let your server consider the url without including the specified folder, but back in the stage it performs needed redirection.
You applied correct rule ,
but the problem is link for the solution of this issue you have to
remove public_html from
your all links and it will automatically redirect to your required
path without public_html.

Yii Framework: Instructions to hide index.php entry script aren't working

I am trying to tidy up my site URL by removing the index.php entry script. There's a documented method to do this, found here: http://www.yiiframework.com/doc/guide/1.1/en/topics.url
The instructions basically to say to set 'showScriptName' to false within the Yii project config file.
They also say to enable the rewrite module within your Apache configuration. I manually enabled it within the httpd file for WAMP. See here. I could have also done it via the system tray interface.
Once that was saved, I restarted by server.
Lastly, (and this is what I'm the least sure about, but I copied it from instructions) I added some lines to the .htaccess file within the protected folder of my Yii Project.
AllowOverride all
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
Despite doing this, I am getting Not Found errors for every single one of my pages. I am unsure as to what has gone on for this to happen, or what I haven't done to enable it properly.
Thanks.
That .htaccess content goes in the .htaccess file in the root directory not the protected folder. It should then work. From http://www.yiiframework.com/doc/guide/1.1/en/topics.url#hiding-x-23x read this:
We can create the file /wwwroot/blog/.htaccess with the following content.
The following settings are what I use for every Yii project. Give that a shot.
.htaccess:
<ifModule mod_rewrite.c>
# Turn on the engine:
RewriteEngine on
# Don't perform redirects for files and directories that exist:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# For everything else, redirect to index.php:
RewriteRule ^(.*)$ index.php/$1
</ifModule>
/protected/config/main.php
'urlManager'=>array(
'showScriptName'=>false,

Avoid public folder of laravel and open directly the root in web server

I was going through all possible sample on internet to solve this. Still it is an headache.
I just want to avoid the 'public' in www.mylaravelsite.com/public/
and make it like www.mylaravelsite.com for the root directory.
Now I do not want to avoid the security concern,So I learned .htaccess would be the best way.
Any solution friends ?
& advance thanks for interacting !
Let's assume you have this folder structure in your server
.cpanel/
public_html/
public_ftp/
..
And the laravel folder structure is
app/
bootstrap/
public/
vendor/
composer.json
artisan
..
You can create a folder name mylaravelsite on your server inline with public_html and public_ftp folder, and copy to it the whole laravel application except the public folder because you will paste all of it contents on the public_html, so you have now:
.cpanel/
public_html/
public_html/packages
public_html/vendor
public_html/index.php
public_html/.htaccess
...
public_ftp/
mylaravelsite/
mylaravelsite/app
mylaravelsite/bootstrap
...
On your public_html/index.php change the following line:
require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/start.php';
to
require __DIR__.'/../mylaravelsite/bootstrap/autoload.php';
$app = require_once __DIR__.'/../mylaravelsite/bootstrap/start.php';
and also don't forget to change /mylaravelsite/bootstrap/paths.php public path, you might use it.
'public' => __DIR__.'/../public',
to
'public' => __DIR__.'/../../public_html',
Your site should be running.
Create .htaccess in root folder and write these line
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
For production server it is recommended that you point your domain directly to the public folder
It sounds like the information you are missing is:
Documentroot
This is also called the "web root". Apache specifically calls it the DocumentRoot - Click that link for the official explanation.
Basically what it does is set which directory the server pulls files from. In Laravel, the document root should be the public folder.
Setting the DocumentRoot to public means that going to http://mylaravelsite.com in the browser will infact be "pointing" to the public folder as you want.
In the .htaccess file (actually, more likely in the virtual host configuration), you can set the DocumentRoot for your site:
DocumentRoot /path/to/laravel-app/public
How you set this up depends on your hosting. Each hosting has different ways to setup a website and so we cannot answer that specifically for you - you should consult your web hostings tech support. The key point is that the public directory should be the web root, while everything else should be "behind the web root".
Fair warning tho: some hosting providers do not give you enough access to accomplish that.
Just add .htaccess file on Laravel root if it's not present and add following lines in it, that's it,
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
create .htacess file in the root directory of your laravel project and put this code in.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]
RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php
point your web directory to public/. If you are using apache this will work:
<VirtualHost *:80>
DocumentRoot /var/www.mylaravelsite.com/public/
ServerName www.mylaravelsite.com
</VirtualHost>
Here is the solution, But Must not do it in real projects, it is just for starter to test Laravel and i have tested it with laravel 5.0 and it is ,cut index.php and .htaccess files from public folder and paste it in the root directory and change these two lines as
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
It is Highly Recommended not to use the above method without testing environment, and should use virtual host instead.
All you just need to change .env file in your laravel project files. if your laravel project inside in
Root/domain/public_html/laravel/
Go to .env file and edit
you need to edit app url path which should be
APP_URL=http://www.domainname.com/laravel/public/
Thats it your project will run now. if your laravel files is in public_html, then your app url must be like this
APP_URL=http://www.domainname.com
Thanks
For Lumen
Let's think you have a folder path like: /var/www/project/microservice(lumen src)
/var/www => document root for localhost/
Target you want:
localhost/project/microservice[/foo...] => localhost/project/microservice/public/foo...
I do this by .htaccess (placed at /project folder) like below:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^.*/public/.*
RewriteCond %{REQUEST_URI} ^(/[^/]+/[^/]+/).*
RewriteRule ^[^/]+(.*)$ %1public$1 [L,R=301,P]
On Server(Apache)
Create .htaccess in the root folder and write below line
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
Lean more on Gist
On Local Development
You can create a virtual host by adding the below line to your apache vhost config file.
Generally, you can find this file in C:\xampp\apache\conf\extra\httpd-vhosts.conf file
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/mysite/public/"
ServerName www.mysite.local
</VirtualHost>

.htaccess for site in sub-directory using Yii framework

I have looked at several examples of htaccess configs for websites within sub-directories, and tried most of them without 100% success.
My setup is:
using Yii framework
htaccess at public_html/.htaccess
site located inside public_html/mysite directory
index handling all requests located at public_html/mysite/frontend/www/index.php
The status of the URLs:
www.mysite.com works fine [ok]
www.mysite.com/controller/action shows me the homepage [wrong]
www.mysite.com/mysite/frontend/www/controller/action works fine [wrong, the item above should work instead]
My .htaccess at the moment looks like this:
AddHandler application/x-httpd-php53s .php .html
Options +SymLinksIfOwnerMatch
IndexIgnore */*
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !^/mysite/frontend/www
RewriteRule ^(.*)?$ /mysite/frontend/www/index.php [L]
I have tried everything, but I have no idea why www.mysite.com/controller/action won't work :(
Any help would be really appreciated! Thanks!
I found the answer to this similar question to be helpful. Here is how my rewrite rules ended up:
#Forward all non-existent files/directories to Yii
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) subdir/index.php/$1 [QSA,L]
This takes all non-existent files/folders and sends them to the yii script with initial url appended. QSA appends any query string that may be present in the initial url.
You didn't mention if you configured Yii's Url Manager for clean URLs. You need to, otherwise Yii expects the "route" to appear as a GET param named "r". If you didn't, consult this section of the definitive guide
You dont need to edit .htaccess. You just need to move the Yii entry script (index.php) and the default .htaccess up from the subdirectory to the webroot (so that they reside directly under public_html). Once you move index.php and .htaccess to the root directory, all web requests will be routed directly to index.php (rather than to the subdirectory), thus eliminating the /subdirectory part of the url.
After you move the files, you will need to edit index.php to update the references to the yii.php file (under the Yii framework directory) as well as the Yii config file (main.php). Lastly, you will need to move the assets directory to directly the webroot, since by default, Yii expects the assets directory to be located in the same location as the entry script).
That should be all you need to do, but if you need more details, I describe the approach fully here:
http://muhammadatt.tumblr.com/post/83149364519/modifying-a-yii-application-to-run-from-a-subdirectory
I also didn't update the .htaccess file, easier to modify the httpd.conf virtual host for the subdomain and change the DocumentRoot to point to your yii folder.

Categories