Im using a Framework which has this .htaccess file:
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !(\.png|\.jpg|\.gif|\.jpeg|\.bmp|\.ico)$
RewriteRule ^(.*)$ entryPoint.php [QSA]
</IfModule>
thats very good, because entryPoint.php runs everytime. But I have a PhpBB forum, placed in SITEROOT/forum directory. It would be the best that in this /forum directory to .htaccess be ignored. How to set a rule to be ignored in a directory?
I'm a bit rusty with my rewrite rules but,
RewriteCond $1 !^/forum
Should work.
Related
In the past, I have got this working no problems at all, but for some reason on my new server I just can't get it to work.
I have the following .htaccess file in the root of my application
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
I have also enabled mod_rewrite and have confirmed this with php_info()
my site is located at /var/www/html/test
Is it possible that although mod_rewrite is enabled that it is not working and if so, how can I test it?
On some server implementations, you'll need to wrap it within <IfModule> tags.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
Also check your httpd.conf file to ensure it has:
Options FollowSymLinks
AllowOverride All
It'd also be worth checking to makesure the .htaccess file isn't being overridden by another .htaccess file.
A simple way to test if .htaccess is working
Simply put the following in your .htaccess file:
deny from All
What this does is deny access to your site from everyone. If you are presented with a 403 forbidden when trying to access the site - the .htaccess file is being included. If not - see above.
I use this on my codeigniter setup
RewriteEngine on
# prevent these directories from hitting CI
RewriteCond $1 !^(index\.php|images|assets|robots\.txt|crossdomain\.xml)
# route everything else to the index.php
RewriteRule ^/(.*)$ /index.php/$1 [QSA]
(my setup is done in the virtualhost of .conf and not in .htaccess, though they are usually about the same configuration)
I have a Silex project. Works on localhost(using php.exe) but I've just transferred it to a subdirectory of an existing website. For example:
www.website.foo/silex/
On the site, because of funky existing routing, the silex app is symbolically linked in the webroot under a /silex/ folder, but is actually elsewhere in the filesystem. The index page works.
I wasn't using an .htaccess file, but I copied the one from the documentation, but it hasn't gotten me anywhere.
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /var/www/webroot/silex/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
I am at a complete loss as to why it doesn't work, let alone what to change to fix it.
Edited .htaccess
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /silex/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Question
Does the .htaccess file have to be in the root directory? Or is being in the application directory fine?
Your RewriteBase directive is wrong, its related to web root, not your filesystem structure, so just use RewriteBase /silex/
I do not know why, but this simple Rule will not work.
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^rubbellos\.png/$ rubbellos/rubbelbild_png.php [NC,L]
RewriteRule ^rubbellos\.css/$ rubbellos/rubbellos_css.php [NC,L]
</IfModule>
If I copy the xyz/rubbellos/rubbelbild_png.php to browser it is OK.
My approach is to bring the request of rubbellos.png to the .php-file. But I get a file not found.
Thx for any hint in advance.
You have 2 errors:
use a RewriteBase since you're talking about a subdirectory /xyz/ in your question.
disable MultiViews option to avoid unexpected behaviour with rubbellos (virtual file and existing directory).
You can replace your current code by this one in your htaccess (which has to be in /xyz/ folder)
Options -MultiViews
RewriteEngine On
RewriteBase /xyz/
RewriteRule ^rubbellos\.png$ rubbellos/rubbelbild_png.php [L]
RewriteRule ^rubbellos\.css$ rubbellos/rubbellos_css.php [L]
Note: don't forget to replace xyz by your real subdirectory's name
For some reason when I deploy my API using Restler's API Explorer (a fork of Swagger UI) to production it gives me a general 404 error when I load:
/api/explorer
When I am more explicit and state:
/api/explorer/index.html
It loads the framing for the page but then reports "404 : Not Found ../resources.json" in red text below the header:
I'm fairly certain there's something environmental flaring up as the same files locally work. I also checked the .htaccess file in the /api/explorer directory and it looks right to me:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^$ index.html [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.html [QSA,L]
</IfModule>
Any help would be appreciated.
It turns out all the problems were down to a mod_rewrite problem. I'm still not 100% on WHY this problem showed up in one environment but not others with precisely the same httpd.conf and .htaccess. Oh well, the solution is to be explicit in the rewrite rule about your base url using the RewriteBase directive.
In the API directory I now have the following .htaccess file:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /api
RewriteRule ^$ index.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
In the API-Explorer directory I now have the following .htaccess:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /api/explorer
RewriteRule ^$ index.html [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.html [QSA,L]
</IfModule>
In order to troubleshoot this problem one invaluable tip that I came across is turning on Apache's mod_rewrite logging.
# Adding logging for Rewrites
RewriteLog logs/rewrite.log
RewriteLogLevel 2
Put this in any globally scoped area of httpd.conf; I put it around the entries that were already there about logging but you can also just put it at the end if you like that better. In addition, the basics around rewrite troubleshooting includes (apologies if this basic):
make sure that your httpd.conf has AllowOverride All and Options FollowSymLinks set for the directories you serving Restler out of.
You can put all of the configuration into httpd.conf and avoid .htaccess files altogether (and it's a bit faster that way too) but if you do that remember that httpd.conf has absolute url referencing versus .htaccess's relative.
You can check the ReadMe file on the Restler Github page
https://github.com/Luracast/Restler-API-Explorer#readme
Did you add the 'Luracast\Restler\Resources' class to create resources.json at API Root?
In your own index.php, the addAPIClass section should look like this:
$r = new Restler();
$r->addAPIClass('Luracast\\Restler\\Resources'); //this creates resources.json at API Root
// ... your own addApiClass
$r->handle();
It is in the documentation under "Use", but I had trouble figuring this out as well...
Make sure you have cache directory with write permission in your api root
.htaccess looks like this:
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !(\.png|\.jpg|\.gif|\.jpeg|\.bmp|\.ico)$
RewriteRule ^(.*)$ entryPoint.php [QSA]
</IfModule>
this enforces all request running though entryPoint.php. This processes all files, redirects, etc. Images are free to go, there can be direct references to them. But what about CSS, JS files? I cant add exceptions - because it would reveal the directory structure. All I want is:
script src="ds.jss" while they can be at "js/" or "module/x/js/". Same with CSS.
I understand I can do it with entryPoint.php: file_get_contents and outputs. It does work, but its too slow. First we tried it with pictures too.
How to enable a "direct access"?
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ entryPoint.php [QSA]
</IfModule>
Try adding these rewrite conditions...
If you don't want to do that within the php file, you need to add a rule:
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^ds\.jss$ module/x/ds.jss [L]
RewriteCond %{REQUEST_URI} !(\.png|\.jpg|\.gif|\.jpeg|\.bmp|\.ico)$
RewriteRule ^(.*)$ entryPoint.php [QSA]
</IfModule>
The important part is the L flag which stands for Last Docs. It will prevent the other rules to run.
If you want to resolve the filename dynamically but you don't want to use PHP to provide the actual file but your apache server, you can still use PHP to resolve the filename by creating a dynamic rewrite map Docs, search for External Rewriting Program.