I've created a WebApp on Mac OS X 10.9. If I just go to something like the index.html it works fine, so I know the apache config there is working. Now I'm trying to get a rewrite rule to work for Restler and am having issues. My httpd.conf file looks like this:
Alias "/dts" "/Library/Server/Web/Data/WebApps/dts"
<Directory "/Library/Server/Web/Data/WebApps/dts">
AllowOverride All
Options Indexes -MultiViews FollowSymLinks
</Directory>
Now I want a path like https://myserver.com/dts/api/foo to redirect to the index.php file in the api directory, so I put a .htaccess file in the api subdirectory:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /Library/Server/Web/Data/WebApps/dts/api
RewriteRule ^$ index.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
<IfModule mod_php5.c>
php_flag display_errors On
</IfModule>
The last line of my rewrite log has the correct path showing:
(1) pass through /Library/Server/Web/Data/WebApps/dts/api/index.php
But what the browser returns is:
The requested URL /Library/Server/Web/Data/WebApps/dts/api/index.php was not found on this server.
If I do an ls -l of that path it's absolutely there. What am I doing wrong?
Related
I want apache to rewrite everything to my index.php, meaning that apache should not process anything, it should ignore the url input and just forward it to the index.php.
I've searched for this many times, and the best solution I found was:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
But today I noticed that if I enter an existing path, apache will show the forbidden page and I don't want that. What I want is to always show the index.php whatever the uri is (obviously the part behind the domain name :P).
I'm using $_SERVER['REQUEST_URI'] to let PHP route everything, using a MVC app, so apache trying to process the url input is very conflicting.
I disabled the indexing, and I'm also thinking on denying access to the document root and allowing only the folder where the index.php is:
httpd.conf:
<Directory "/srv/http">
Options -Indexes +FollowSymLinks
AllowOverride None
Require all denied
</Directory>
vhost.conf:
<VirtualHost *:80>
ServerName example.com
#Redirect permanent / http://www.example.com/
DocumentRoot "/srv/http/example.com/www"
<Directory "/srv/http/example.com/www">
Require all granted
<Files "index.php">
SetHandler "proxy:unix:/run/php-fpm/www.example.sock|fcgi://localhost/"
</Files>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
</Directory>
<IfModule dir_module>
DirectoryIndex index.php
</IfModule>
</VirtualHost>
I even want to only allow access to the index.php file, but maybe this is overkill?
Moving Require all granted inside the <Files> block does not work, but this is secondary and you'd probably discourage me from trying (probably is not even possible, or necessary).
So, how can I prevent apache from processing the urls? To let my MVC app take care of the routing.
Well the rewrite code you are using specifically excludes existing URLs, so just stop that. You don't need the RewriteBase either.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteRule . index.php [L]
</IfModule>
If you need more, let me know, but looks like that should put you on the right track for what you're trying to achieve. Don't you have any image files, CSS and such you want Apache to serve itself? That's the usual reason for excluding existing URLs.
I have a folder called crm in htdocs which contains a fresh laravel 5.1
project and i am trying to acess it via http://localhost/crm/
but it just brings the index of page containing the directory contents
instead of the page mapped in my routes.php as
Route::get('/', function () {
return view('panel');
});
i have checked that apache mod_rewrite is enable in httpd.conf
LoadModule rewrite_module modules/mod_rewrite.so
DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
then the .htaccess file in crm/public folder contains
<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>
I have also tried to change it to
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
without success.
You need to point Laravel to public directory to make it work. For example, if you've installed Laravel in C:/xampp/htdocs/ directory, you need to use these settings:
DocumentRoot "C:/xampp/htdocs/public"
<Directory "C:/xampp/htdocs/public">
Do not edit .htacces inside public folder. Try to change settings and load Laravel website by going to localhost first.
When you've edited Apache config file, you should restart web server.
I'm currently attempting to install Anchor CMS on my Apache server.
I have successfully deployed it to the server. That is, when I go to www.domain.com, I am greeted with the default-themed front page and a test post :)
However, if I try to click the post, or go to the admin area, I get an error such as:
Not Found: The requested URL /posts/hello-world was not found on this server.
However, if I follow the (in this case) post link using a direct link, such as:
www.domain.com/index.php/posts/hello-world
It works completely fine. So, it appears to be a problem with the rewriting.
I found another problem on Stackoverflow exactly like mine, located here
Unfortunately, I did the same steps and nothing works. Just to recap, this is how my VirtualHost looks:
<VirtualHost *:80>
ServerName www.domain.com
ServerAlias domain.com
DocumentRoot /var/www/domain.com/public_html
<Directory /var/www/domain.com/public_html>
AllowOverride All
Require all granted
</Dictory>
</VirtualHost>
And this is how my Anchor CMS config.app file looks:
return array(
'url' => '/',
'index' => '',
...(rest of the data here)...
As the documentation states to use an empty index in this default case.
My .htaccess currently looks like this:
Options -indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
And it is located in the document root "public_html"
Sadly, even with these things configured, I still get the "Not Found" errors. I don't really know where to go from here :(
EDIT
Options -indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^ http://google.com [R,L]
RewriteBase /
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
I tried to put in a general rewrite to the .htaccess file, and it seems like it's not being executed:
It appears that the mod-rewrite is not being loaded.
See your server configuration file (httpd.conf). There should be a statement as follows:
LoadModule rewrite_module modules/mod_rewrite.so
If the line starts with #, remove the # character. You can also use the command:
a2enmod rewrite
Also, try to shift your Rewrites outside of the IfModule block.
Options -indexes
RewriteEngine On
RewriteBase /
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [L]
I want to use mod_rewrite with Wampserver to remove "/index.php/" from addressbar. This code is suggested with Codeigniter Framework:
RewriteEngine on
#RewriteBase /
RewriteCond $1 !^(index\.php|img|table-images|robots\.txt|css|fonts|js|uploads|dbg-wizard\.php)
RewriteRule ^(.*)$ index.php/$1 [L]
This should change this url:
mysite.local/contact_us
to this:
mysite.local/index.php/contact_us
This works with XAMPP but with Wampserver first URL generates Error 404!
I enabled mod_rewrite with Apache and there is no errors in error log.
Update:
I added .blabla in .htacess but nothing happened! It means that Apache does not read .htaccess! Why?
I added AllowOverride All to httpd-vhosts.conf.
Apache did not execute .htaccess and enabling AllowOverride in httpd.conf is not enough.
This is my httpd-vhosts.conf file:
<Directory E:\mysite\www>
Options Indexes FollowSymLinks Includes ExecCGI
#Order Deny,Allow
#Allow from all
AllowOverride All
Require all granted
</Directory>
To check that mode rewrite is working or not try these steps:
Make a folder in your root directory called htaccess_test
Create a .htaccess file, and put these code into this and save it.
options +FollowSymLinks RewriteEngine On
RewriteBase /htaccess_test/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)/?$ user.php?u=$1
Create one more file called user.php and put these code into
this and save it.
<?php
if(isset($_GET['u'])){
echo $_GET['u'];
}
Now go to browser type http://localhost/htaccess_test/put_some_value_here.
If that is working than the problem is not in your apache setting.
Make sure you are editing the right .htaccess file. The .htaccess file you need to edit is in your projects' root folder, not in application or any other folder. And put these code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /root_directory_of_your_project/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
I am using this apache rewrite, when i am on my local machine.
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /skoleskak/web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
But after i uploaded it, to my host i get server error. They told me they dont support Options, but i can't get it working without that.
I am trying to route my Silex installation, so its /web/stats/ instead of web/index.php/stats.
I found this example for Codeigniter http://www.chrishjorth.com/blog/one-com-codeigniter-htaccess-rewrite-rules/
Anyone know how to make it work with Silex?
Same problem at some hosters. If your server has installed Apache >= 2.2.16 you can use the FallbackResource command:
FallbackResource /index.php
in your .htaccess instead of
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /skoleskak/web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
See also Apache’s fallbackresource: your new .htaccess command for more information.