Apache Alias / PHP / Laravel oddity - php

The problem description is very specific, but i have no idea about its source
The project uses Laravel 5.1
I have a project copy on my computer and remote server. Local server is configured to remove /public from URL with VirtualHost. On remote server, project is located in subdirectory. E.g. /project. To get rid of public, there is an alias in httpd.conf and line RewriteBase /project in /project/public/.htaccess
The problem appears when using Laravel's pagination mechanism:
There are links to pages in the page with navigation. On local machine everything is OK, but on remote server clicking on link with URL like http://<server_ip>/project/navigationPage?page=N causes redirect to http://<server_ip>/navigationPage?page=N. Of course, 404 error appears.
What is the problem and how to fix it?
Full .htaccess in /project/public:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /project
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

Ok, problem was in slash that was added to links by paginator. Link was looking like http:///project/navigationPage/?page=N, but must look like http:///project/navigationPage?page=N (without slash). Bug fixed by editing AbstractPaginator's url function:
public function url($page)
{
if ($page <= 0) {
$page = 1;
}
$parameters = [$this->pageName => $page];
if (count($this->query) > 0) {
$parameters = array_merge($this->query, $parameters);
}
return rtrim($this->path, '/').'?'
.urldecode(http_build_query($parameters, null, '&'))
.$this->buildFragment();
}

Related

CodeIgniter 3 Routing Issue

I used CI's routes and have the following entry in config/routes.php
if($subdomain == 'debug')
{
$route['debug/(:any)'] = "admin/debug/$1";
}
elseif($subdomain == 'dev')
{
$route['models/(:any)'] = "v2/dev/models/$1";
}
If I were to browse to
dev.mydomain.com/models/test/
everything works fine and I get the correct output.
However, I were to browse to
dev.mydomain.com/models/test/trip_id/9091
I will get a 404 Error page.
Only way to make it to work is to use the following route entry.
$route['models/(:any)/(:any)/(:any)'] = "v2/dev/models/$1/$2/$3";
What really confuses me further is that it works if I were to browse to
debug.mydomain.com/debug/test/trip_id/9091
What am I missing here as the route entries looks similar but will only work on the first subdomain (debug.mydomain.com) but not on the latter (dev.mydomain.com)
This is the content of my .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
Any help is greatly appreciated.
$route['models/(:any)'] = "v2/dev/models/$1";
Check the route path if you are calling the controller from the folder
it should be yourfolder/controller/method_name/$1

Laravel remote server error 500, site doesn't works

It's my first upload to a remote server of a Laravel site.
Local I have configured a vhost so my access to my site is like:
site.domain.com //it's pointing htdocs/laravel-proyect/public
I have uploaded my site to my remote server, then:
Change permisions on storage and all its directories
Change permisions to bootstrap
Change configuration of app.php
'url' => 'http://site.domain.com',
Change configuration in database.app with new parameters (as well as in email.php)
Load all tables and data in the data base
Then I try to load my site and get a 500 Internal Server Error
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
It works a little, I have this code in routes.php:
// Begins in the login view
Route::get('/', function()
{
if (!Sentry::check()) {
$data = array();
if (Session::has('email')) {
$data = array('email' => Session::get('email'));
}
return Redirect::route('login', $data);
}
else
return Redirect::route('users');
});
/ ========================================
// LOGIN, LOGOUT AND ACTIVATION SECTION ==========
// // ============================================
// show the login page
Route::get(MyHelpers::textLang('login','routes'), array('as' => 'login', function()
{
if (Sentry::check())return Redirect::route('users');
else {
$rules = User::$rules_login;
// show the login page (app/views/frontend/login.blade.php)
return View::make('frontend.login', compact('rules'));
}
So at first time mo url look like:
site.domain.com/entrar
'entrar', (login in spanish), y set by MyHelpers::textLang('login','routes'), access to my class MyHelpers and to lang files to translate 'login' in to 'entrar', but dont load the template.
Begins to :
Read documentation, making some changes: deleting Multiviews from
.htaccess (deprecated), adding RewriteBase to .htaccess too.
Copy /public content to base dir and change paths in bootstrap/paths and
in the index.php files.
Reinstall in two remote servers to verify is not my provider failing (same error). Talking to my provider, supouse
there are no errors on the server.
I create a new htaccess in the base dir redirecting routes to /public.
Try with php 5.4, 5.5 and 5.6
Actually my .htaccess is:
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
And I have no more ideas and cant find other solutions as related here.
Any idea? Please, I'm getting crazy, on wensday I have to beguin a new proyect and still working with this one.
Thanks
I have to add
RewriteBase /
to the .htaccess
I have a demo laravel application on heroku Simple Blog.My .htaccess file is:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
#other lines for gzip
It seems that there is no issue with your .htaccess file. It may be problem with you code logic. If you are getting no error with same code on localhost, then check your config again. For laravel 4, there is already a similar issue on stackoverflow Laravel 4 Virtual Host and mod rewrite setup
Note that laravel 5 (if you are using it) takes input (database connection and other setting) from .env file.
If you are still getting error then try to send simple response on index page like:
Route::get('/','basic configurations are correct');
and then make it complex step by step. It will help you in finding error.
Answer from #kikerrobles really works.
your final .htaccess file should look like following
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteBase /
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

Fatfree Framework error 404 on every route

This is working localy on my WAMP server, but when I tried to use it on my host it always gets an error:
HTTP 404 (GET /)
• teste/index.php:17 Base->run()
You can see the error here: http://rafaelmsantos.com/teste/
I don't have a clue whats going on, I've tried different .htaccess but it display always the same error.
.htaccess
# Enable rewrite engine and route requests to framework
RewriteEngine On
# Some servers require you to specify the `RewriteBase` directive
# In such cases, it should be the path (relative to the document root)
# containing this .htaccess file
#
# RewriteBase /
RewriteRule ^(lib|tmp)\/|\.(ini)$ - [R=404]
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L,QSA]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
config.ini
[globals]
AUTOLOAD=public/pages/
DB.dns="mysql:host=localhost; dbname=lod; port=3306;"
DB.user="root"
DB.password=""
DEBUG=3
UI=assets/
index.php
<?php
$lod = require('lib/base.php');
$lod->config('config.ini');
// HELPERS DEVELOPED BY ME
require_once 'helpers/base_helper.php';
//*-----------------------------------------------------------------*/
//* PÁGINAS */
//*-----------------------------------------------------------------*/
$lod->route('GET /', 'PagesController->index');
$lod->route('GET /project/#page', 'PagesController->index');
$lod->run();
And my folder structure:
try to set the RewriteBase in your .htaccess (as the comment above said):
RewriteBase /teste/
Turns out I had to autoload in another way,
insted of AUTOLOAD=public/pages/ on config.ini, I had to use $lod->set('AUTOLOAD','public/pages/'); after the require_once and before the routes.

PHP htaccess rewrite rules with wordpress

I have a running service that lets my user choose their own URL address (example: http://hsdfhdfghfh.com/theUserURL)
Now I'm going to put my front site on a wordpress but keep my app running along-side with it.
Now for the problem, i've set a rule in htaccess to forward my users url to their page, but wordpress also needs the same rule in order to make pretty URL (permalink).
Here is my htaccess with my code and the code that wordpress injected. Currently only my redirect is working, how can I make them both work together?
Can I add a code in my php file that gets the URLs and if it has no entries I throw it to wordpress to show?
This is my htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ ./url.php?w=$1
AddDefaultCharset UTF-8
# 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
And this is my php (url.php) file that handles the redirects:
<?php
session_start();
$url_name = $_GET['w'];
include ('init.php');
$result = mysql_query("SELECT * FROM urls WHERE url='$url_name'");
$num_rows = mysql_num_rows($result);
$query_result = mysql_fetch_assoc($result);
if($num_rows == 0){
include($theurl.'/404.php');
exit();
}
$_SESSION['url_id'] = $query_result['url_id'];
?>
..Shows the rest of the page for the user with the specified url_id session...
Maybe instead of showing the 404.php page I could transfer the entered URL to wordpress somehow?
Cheers!
After trying different approaches and trying to manipulate using .htaccess I realized that this process is very bad for loading times and overloading the server.
I ended up moving Laravel to a subdomain :/
Don't try to put Wordpress and Laravel together on the same domain unless you really want to tweak wordpress to the core.

Porting htaccess rewrite rules to hiphop-php config

I have a CodeIgniter project that requires rewriting rules to navigate controllers/views and the like. I have correctly installed hiphop-php on Ubuntu 12.04 and it works perfectly, including with the sample WordPress installation and rewrite rules provided on their site.
However, I need to figure out the proper rewrite rules that will work with the CodeIgniter index.php/controller setup and I haven't had much luck myself.
Here is a sample hiphop-php config file for WP rewriting:
http://www.hiphop-php.com/wp/
VirtualHost {
* {
Pattern = .*
RewriteRules {
dirindex {
pattern = ^/(.*)/$
to = $1/index.php
qsa = true
}
}
}
}
StaticFile {
FilesMatch {
* {
pattern = .*\.(dll|exe)
headers {
* = Content-Disposition: attachment
}
}
}
And here's a sample CodeIgniter mod_rewrite file for Apache:
http://www.farinspace.com/codeigniter-htaccess-file/
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
### Canonicalize codeigniter URLs
# If your default controller is something other than
# "welcome" you should probably change this
RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ / [L,R=301]
RewriteRule ^(.*)/index/?$ $1 [L,R=301]
# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
###
# Removes access to the system folder by users.
# Additionally this will allow you to create a System.php controller,
# previously this would not have been possible.
# 'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Basically all I need the rewriting to do is route the requests properly with the index.php controller of CodeIgniter, which seems to be what the last part of the apache rewrite rules do. The rest I can hack together after seeing some examples.
Thanks a bunch!
As is generally the case, I figured this one out via self-study and some pushing in the right direction from Trip's answer above. I wrote up how to use nginx as a proxy and how to push PHP requests through nginx.
http://www.kyleboddy.com/2013/05/02/facebooks-hiphop-engine-when-to-use-it-and-getting-it-to-work-with-codeigniter/
I don't have enough reputation to post a comment on SO, but...
https://github.com/facebook/hiphop-php/blob/master/hphp/doc/options.compiled
It doesn't look like there's a way to duplicate the -d or -f flags in the HHPHP config, but the documentation of the options isn't exactly thorough. If it's possible, it has to look something like this:
* {
pattern = ^(.*)$
to = /path/to/codeigniter/index.php/$1
qsa = true
conditions {
-d {
pattern = %{REQUEST_FILENAME}
type = request
negate = true
}
-f {
pattern = %{REQUEST_FILENAME}
type = request
negate = true
}
}
}
Have you tried anything along these lines? EDIT: Maybe swap the -d and -f file flags with the %{REQUEST_FILENAME} piece. I could have that backwards. Again, the documentation isn't very illuminative, and I'm just spit-balling.
Use NGINX as frontend for hiphop php. As a plus You are get better performance for serve static files.

Categories