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.
Related
For a web-application I would like to rewrite the URL.
From:
http://example.com/api/logger/all
To:
http://example.com/api/index.php/logger/all
So I tried the following:
RewriteEngine On
RewriteCond %{REQUEST_URI} !/index.php/
RewriteRule ^api(.*)$ api/index.php$1 [L]
I also testet it successfully with http://htaccess.madewithlove.be/.
On the server I get a 404.
My project struct looks like following:
--api
----index.php
--htaccess
--index.html
Update:
I found a solution for external redirects.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !(index\.php)
RewriteRule ^api/(.*)$ /api/index.php/$1 [R=302]
But I need a internal redirect and if remove [R=302] I get 404 with "No input file specified." as response.
Following htaccess file works for
http://example.com/logger/all.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !(index\.php)
RewriteRule ^(.*)$ /api/index.php/$1
But adding api again results in "No input file specified."
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !(index\.php)
RewriteRule ^api(.*)$ /api/index.php/$1
mod_rewrite is a double-edged sword that is incredibly easy to misuse.
Apache 2.2.16 and later provide the extremely useful but surprisingly seldom used FallbackResource directive.
So use the following layout:
--api
----.htaccess
----index.php
--index.html
And use the following contents for your .htaccess file:
FallbackResource /api/index.php
The main difference with the mod_rewrite based solutions is that there is no substitution in the URI, so you have to parse the URI in PHP using $_SERVER['REQUEST_URI'].
For example here, if you access http://example.com/api/logger/all, your index.php file will see the following value:
echo $_SERVER['REQUEST_URI']; // prints /api/logger/all
The main interest of putting the .htaccess file in the api directory is that it ensures that only URLs under the /api prefix are handled by FallbackResource. Any URL that would cause a 404 error in the document root folder will not trigger a call to /api/index.php.
I started an app based on Angular.js and Silex for the server side.
I would use real URL (without hash) but it's not working.
I have activate pushstate on angular with the following line :
$locationProvider.html5Mode(true);
but I don't know how to configure server. Actually when I try to access to localhost/test angular did nothing but silex said : *No route found for "GET /test" ..
my htaccess is like it :
<IfModule mod_rewrite.c>
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine On
RewriteBase /web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) index.php [L]
Structure of my project is Like it
|--app/
|----app.php
|----controllers/
|-------MainController.php
|--web/
|----index.php
|----js/
|---------app.js
...
Thanks you for your help
edit :
route declaration :
config(['$routeProvider, $locationProvider', function($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true);
$routeProvider.when('/test',{
templateUrl : '/cuisine',
controller : 'CookController'
});
}
I am using this on my site, and its working , please give it try. Otherwise i suggest you turn on mod_rewrite logging in apache and look to logs
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
RewriteRule ^ /index.html
Your problem is with RewriteBase. The rewrite base is based on URI folder and you're requesting /test not /web/test, so your rewrite base should be /
I'm just guessing but I think your document root is /path/to/your/project/web (it should be this, only the web directory is meant to be public!) so your .htaccess shouldn't have the RewriteBase on your case.
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>
I have a web directory structure like so:
root
/content
/plugins
/myplugin
/Slim (folder containing Slim Framework)
index.php
/other_folder_1
/other_folder_2
.htaccess
index.html
I'm interested in what to specify in my .htaccess file in order to refer to a directory that isn't actually present on the server, but actually point to the Slim app in the /myplugin directory.
Here are a few example URLs, which I'd like users (or myself) to be able to use in the browser's location bar, or link with in documents:
1. http://example.com/nonexistent_dir
2. http://example.com/nonexistent_dir/info
3. http://example.com/nonexistent_dir/info/details
I'm trying to rewrite these URLs to the following:
1. http://example.com/content/plugins/myplugin/index.php
2. http://example.com/content/plugins/myplugin/index.php/info
3. http://example.com/content/plugins/myplugin/index.php/info/details
...which would all actually be handled by the index.php Slim Framework app in the /myplugin directory. It's important the apparent URLs remain as they appear in the first example, without being changed in the location bar.
Here's what is currently in the .htaccess file in the root directory:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/schedule [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /content/plugins/myplugin/index.php [QSA,NC,L]
</IfModule>
This redirects all 3 of the test examples to http://example.com/nonexistent_dir, using the / route. So my thought is that I should be capturing everything after the nonexistent_dir, whether it be something or nothing, and appending it to the end of the RewriteRule somehow. But I don't understand how.
I realize that using parentheses around an expression will enable me to use the contents as a variable, referred to it with $1 (or $2, $3... for multiples), but I don't know how to apply it to this solution.
Any help will be most appreciated.
Try:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^nonexistent_dir(/.*)?$ /content/plugins/myplugin/index.php$1 [L]
Slim actually discards the base directory, and sets $env['PATH_INFO'], taking the content of this variable to match against the specified routes.
For example, lets take a /sub/index.php (Slim index file) and this rewrite rule:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^somedir(/.*)?$ /sub/index.php$1 [L]
...and this route specification:
$app->route('/info', function() use ($app) { ... });
So, with a GET request to /somedir/info, Slim strips /somedir from REQUEST_URI and sets $env['PATH_INFO'] with value /info (this is actually done in the constructor of \Slim\Environment class).
Later, the Router class will match /info and execute the closure function.
If you want to pass parameters via url, the route would be, for example:
$app->get('/info/:param', function($param) use ($app){ ... })
In webapp2 (python) you can map urls to classes in one file.
app = webapp2.WSGIApplication([('/', pgMain), ('/test/', pgTest)], debug=True)
How would I setup such a thing in php & apache?
Thanks
EDIT:
What I am after is everything after a foldername to be redirected to a file in that folder. eg.
/version/1.0/test/folder/ => /version/1.0/index.php & var="/test/folder"
/version/1.0/another/ => /version/1.0/index.php & var="/another"
Thanks.
Simplest way for doing this is to create .htaccess file in your app folder and put this code there:
RewriteEngine On
RewriteBase /
RewriteRule "(^|/)\." - [F]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [NC,NS,L]
Please note that you need to modify "RewriteBase" directive and put path of your application there "/" means your document root.
After creating .htacess file all requests will be routed to your index.php file and you can access URI via PHP's super global variable $_SERVER['REQUEST_URI']