Rewriterule alias matching directory name? - apache

Is it possible to create a rule that matches an existing directory?
As in the following example:
RewriteRule ^foo$ foo.php
Considering that is also a folder called "foo", Apache tries to open the directory instead of parsing the rule. Is it possible that the rule precedes the directory?
thank you
Testing with the following config:
Options +FollowSymlinks
Options -MultiViews
RewriteEngine on
AddDefaultCharset iso-8859-1
RewriteRule ^foo$ foo.php
And receiving the following error from apache: [Fri Mar 07 15:06:34 2014] [alert] [client 127.0.0.1] C:/htdocs/www.acasa.org.br.v2/.htaccess: Option MultiViews not allowed here

You need to use -MultiViews for it to ignore the folder.
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule ^foo/?$ foo.php [L]
You can toggle DirectorySlash on and off with:
DirectorySlash Off
However the suggested way to resolve your images issue is by using:
<base href="http://www.domain.com/" />

Related

Apache cant load Files of localhost, returning error 500

My server isnt loading direct links on its header of html pages.Where dev.pauloxavier.com is an alias for 127.0.0.1. Example:
http://dev.pauloxavier.com/certified/framework/assets/css/custom.css
http://dev.pauloxavier.com/certified/framework/assets/css/bootstrap.css
I cant access this file direct on the browser, either. Error 500 is returned.
On the log of errors i got:
[Mon May 11 12:26:28.724782 2015] [cgi:error] [pid 2864:tid 1828] (9)Bad file descriptor: [client 127.0.0.1:51598] AH01222: don't know how to spawn child process: E:/GitHub/certified/framework/assets/img/favicon.png, referer: http://dev.pauloxavier.com/certified/
My htaccess file:
RewriteEngine On # Turn on the rewriting engine
RewriteBase /certified/
RewriteRule ^user/([a-z]+)/?$ user.php?id=$1 [L]
RewriteRule ^([0-9a-zA-Z-_]{1,100})/?$ index.php?to=$1 [L]
RewriteRule ^import/([0-9a-zA-Z-_]{1,100})/?$ index.php?to=import&id_evento=$1 [L]
RewriteRule ^evento/([0-9a-zA-Z-_]{1,100})/?$ index.php?to=evento&id_evento=$1 [L]
RewriteRule ^inserir/([0-9a-zA-Z-_]{1,100})/?$ index.php?to=inserir&id_evento=$1 [L]
RewriteRule ^remover/([0-9a-zA-Z-_]{1,100})/([0-9a-zA-Z-_]{1,100})/?$ index.php?to=remover&id_evento=$1&id_participante=$2 [L]
RewriteRule ^envio/([0-9a-zA-Z-_]{1,100})/?$ index.php?to=envio&id_evento=$1 [L]
RewriteRule ^certificado/([0-9a-zA-Z-_]{1,100})/([0-9a-zA-Z-_]{1,100})/?$ index.php?to=certificado&evento=$1&particip=$2 [L]
My directory on apache is configured as:
<Directory "E:/GitHub/certified">
AllowOverride All
Require all granted
Allow from all
</Directory>
And using the alias:
ScriptAlias /certified/ "E:/GitHub/certified/"
What is most strange is: This version is working on my webserver, and used to work on my local, but i lost my hd, and had to reinstall everything from scratch. I really think that is a problem with apache, like a misconfig.
Thanks in advance!

Laravel sends the server on 10 redirects?

Getting error message:
[Sun Jun 02 12:43:33.579095 2013] [core:error] [pid 4964:tid 808] [client 127.0.0.1:56964] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a
When trying to use laravel to do routing. My routes are as follows:
Route::get('/', 'HomeController#showWelcome');
Route::get('history', 'HistoryController#showHistory');
And my .htaccess:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
And my alias:
Alias /wunhopkuendo/ "c:/wamp/www/wunhopkuendo/public/"
<Directory "c:/wamp/www/wunhopkuendo/public/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
</Directory>
I had this problem as well, and I solved it with the following line on the .htaccess file:
RewriteBase /
If you are using Laravel in a subfolder, you need to follow these steps:
Assuming that you use WAMP with the default installation directory (i.e. c:\wamp)
Insert the RewriteBase line in your .htaccess file with the subfolder of your Laravel instalation.
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /subfolder
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
<IfModule>
Set the application URL on file c:\wamp\www\subfolder\config\app.php
'url' => 'http://localhost/subfolder',
Create a configuration file on alias directory c:\wamp\alias\subfolder.conf with this content:
Alias /subfolder "c:/wamp/www/testando/public"
<Directory "c:/wamp/www/subfolder/public">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Allow from all
</Directory>
Check if your public folder is setup properly
In my case the .htaccess in public folder was missing because of that it was throwing this redirect error. Make sure that your "public/.htaccess" file is available. Hope its helps.

htaccess rewrite - 404 on existing file

So I have the following rewrite in an htaccess file:
RewriteRule ^([^/.]+)/?$ index.php?page=$1 [L]
Whenever I try to go to http://domain/index I get a 404, but when I try to go to http://domain/index. or even a non-existent page like http://domain/a, the rewrite works just fine and index.php var_dump()s the appropriate values.
The only code in index.php is var_dump($_GET);, so I know it's not a php issue.
Can someone explain to me what's wrong with my rewrite rule, and explain how to fix it?
EDIT:
I forgot I had error logging enabled. The error it keeps saving to error.log is:
[Sun Feb 24 21:01:18 2013] [error] [client 192.168.1.1] Negotiation: discovered file(s) matching request: /path/public_html/index (None could be negotiated).
By the error, it seems MultiViews is enabled.
You may try this at the top of the file:
Options +FollowSymlinks -MultiViews
Additionally, I suggest the following:
# Prevent loops
RewriteCond %{REQUEST_URI} !index\.php [NC]
RewriteRule ^([^/]+)/? index.php?page=$1 [L]
MultiViews provides for Content Negotiation, best described here
When MultiViews is enabled (Options +MultiViews), the Content Negotiation module looks for files that match index, but .php files don't qualify for a match, so it fails with None could be negotiated. You can add .php handlers as matches using:
MultiviewsMatch Handlers Filters
as documented in MultiviewsMatch.

Apache htaccess file, where did I go wrong?

Really can't find my mistake, I can access the sitemap/ link, but all the others give a 404 Not Found Error.
DirectoryIndex index.php index.php?page=home index.php?page=error
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
<IfModule mod_rewrite.c>
RewriteEngine On
# some other stuff #
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteBase /
RewriteRule ^sitemap/?$ sitemap.xml.php [L]
RewriteRule ^([a-zA-Z]+)/?$ index.php?page=$1 [L]
RewriteRule ^products/?$ index.php?page=products [L]
RewriteRule ^products/([0-9]+)/?$ index.php?page=products&id=$1 [L]
</IfModule>
I'd really appreciate some help, I definitely suck at .htaccess files...
Rewriting rules aside, you have other problems here:
DirectoryIndex index.php index.php?page=home index.php?page=error
This means, that, for a folder a file showing index will be selected in this order (first one existing wins):
index.php
index.php?page=home (this is the filename)
index.php?page=error (this is the filename)
I doubt this was your intention.
Next:
AllowOverride All
If you're already in .htaccess and AllowOverride was restrictive, this will not help, and if it wasn't, then there is no point of writing this again.
Order allow,deny
Allow from all
This basically says "allow everyone everywhere" which is the default anyway. Unless it was restricted in some way on upper level or in apache configuration, this is redundant.
As for rewrite:
RewriteRule ^([a-zA-Z]+)/?$ index.php?page=$1 [L]
RewriteRule ^products/?$ index.php?page=products [L]
The second rule is redundant anyway, and will never be reached (as the first one matches it as well).
As for the error you're seeing:
[Wed Jul 04 02:56:30 2012] [error] [client 127.0.0.1] File does not exist: /var/www/home"
This may mean problems with DocumentRoot definitions. Please, post your VirtualHosts configuration.

How can I have rewrite rules with aliases?

I apologize in advance if this is too long. I figure more detail is better than less and hope I'm not being horribly rambling :-)
I use WAMP on my laptop for local dev, and I have various c:/wamp/alias/* files each pointing to a project working directory. I've had some excellent mod_rewrite help and gotten
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*\/)?ih(\/.*)?$ $1index.php$2 [L,QSA]
to work to change localhost/.../ih/sub/dir to localhost/.../index.php/sub/dir for URLs that are both SEO-friendly and short. [I haven't gone on to do this in prod but I suspect it will work just as well.] However, to get it all together I had to change my doc root from c:/wamp/www/ to c:/, which I'd really rather not do just in case my Apache gets hacked and otherwise because it's a kludge.
My test alias file looks like
Alias /testme "c:/var/tmp/wamp-testme/"
<Directory "c:/var/tmp/wamp-testme/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*\/)?ih(\/.*)?$ $1index.php$2 [L,QSA]
</Directory>
and the error I get when trying to load http://localhost/testme/rewrites/ih/sub/path is
[Thu Jun 30 06:46:13 2011] [error] [client 127.0.0.1]
File does not exist: C:/wamp/www/var
with a matching
Not Found
The requested URL /var/tmp/wamp-testme/rewrites/index.php/sub/path
was not found on this server.
in the browser. Sure enough, the same config in my c:/wamp/alias/flying.conf file that points to the c:/data/flying/ directory throws File does not exist: C:/wamp/www/data in the error log file, and so on.
Sooooo... How can I have a rewrite rule that transcends aliases without having my doc root at my machine root dir?
Odd: try adding a PT flag to the rewrite rule: this forces the re-written URL to be sent back to the URL mapping engine.
EDIT: try setting the RewriteBase on the Directory.