Phalcon Routing exclude Routing to Controllers when File Exists - phalcon

I have some css .map files directly under assets folder, however for some reason they failed to load and i get a 404 error in the dispatcher and router. Any solution on how to fix this issue ? i added following config to the router but still get the error.
$router->add(
'/assets/css/dashboard-free.css.map'
);
Error log says
example.com/assets/css/dashboard-free.css.map:
2019-02-13 07:02:58:
Phalcon\Mvc\Dispatcher\Exception: IndexController handler class cannot be loaded
File=/var/.../Module.php
Line=27
#0 [internal function]: Phalcon\Mvc\Dispatcher->_throwDispatchException('IndexController...', 2)
#1 [internal function]: Phalcon\Dispatcher->dispatch()
#2 /var/.../Module.php(27): Phalcon\Mvc\Application->handle()
#3 /var/.../web/index.php(12): Admin\Module->main()
#4 {main}

Apache
Try this in your .htaccess file
AddDefaultCharset UTF-8
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)\.(\d+)\.(bmp|css|cur|gif|ico|jpe?g|js|png|svgz?|webp|webmanifest)$ $1.$3 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^((?s).*)$ index.php?_url=/$1 [QSA,L]
</IfModule>
nginx
location ~* (.+)\.(?:\w+)\.(bmp|css|cur|gif|ico|jpe?g|m?js|png|svgz?|webp|webmanifest)$ {
try_files $uri $1.$2;
}

i don't think this has anything to do with phalcon or php
i would check the css file for the map path
/*# sourceMappingURL=dashboard-free.css.map */

Related

.htaccess Remove filename from url

I'm trying to remove: "site.php" from my url:s, which look like
"example.com/custom-foldername/site.php", so the url:s would look like "example.com/custom-foldername"
Currently it's not working at all. Basically my site just doesn't change the url. I know that the .htaccess file is being read, because if i write junk code in it, it gives error 500.
Here is my current .htaccess code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
Options -Indexes
RewriteRule ^site\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /site.php [L]
</IfModule>
The code you posted is a front-controller pattern - it rewrites every request for non-existent files to /site.php in the document root (not /custom-foldername/site.php).
And nor will a RewriteRule pattern like ^site\.php$ match a request like /custom-foldername if the .htaccess file is in the document root.
I'm trying to remove site.php from my URLs...
From all your URLs? Is site.php present in all your URLs? So, site.php is your front-controller?
If site.php really is your front-controller then try something like the following instead:
Options -Indexes
RewriteEngine On
RewriteBase /custom-foldername
RewriteRule site\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ site.php [L]
This rewrites everything that doesn't map to a physical file or directory to /custom-foldername/site.php.
UPDATE: I solved this my myself while ago, but forgot to update
So, i found the solution and here's my current .htaccess file, if someone is ever having the same problem
RewriteEngine On
RewriteBase /
Options -Indexes
DirectoryIndex site.php site.html
When user "asks" for folder directory (example.com/cats) apache looks for "site.php or site.html" files inside it. (example.com/cats/site.php) If it finds either on of them it displays it to the user as (example.com/cats). If either file isn't found it gives normal "404 not found error"

File Manager of CKEditor WolfCMS not working with Nginx

I migrated a WolfCMS from Apache to Nginx. Everything is working fine except for the CKEditor File Manager plugin. When opening the browser server box of CKEditor I am seeing No input file specified. All other friendly URLs, rewrites are working without any issues. So I assume the issue is related to a wrong Nginx configuration.
These are the Apache rewrites:
RewriteEngine On
# Set next line to your Wolf CMS root - if not in subdir, then just /
#RewriteBase /wolfcms/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
# Main URL rewriting.
RewriteRule ^(.*)$ index.php?WOLFPAGE=$1 [L,QSA]
For Nginx the docs just state:
#Put the following code in your server block:
try_files $uri $uri/ /index.php?WOLFPAGE=$uri&$args;
And that is what I did. The file manager URL that is not working in Nginx is:
/wolf_ckeditor/filemanager/index.php?type=Images&CKEditor=part_0_content&CKEditorFuncNum=1&langCode=de
=> Leading to No input file specified.
Any suggestions on how I could modify my Nginx config to get this working again?

.html removal from URL using .htaccess rewrite rules

I have a static website - a bunch of static html pages. I am trying to remove .html part from the URL of my webpages. I have used an .htaccess file with the following code to do that:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
However, I am getting a 404 error. For example:
The requested URL /home/username/public_html/contact.html was not found on this server.
Ideally, it should redirect to /~username/contact.html.
Addition information
When I used "Options -MultiViews" line above the code it is giving the following error:
500 Internal Server Error: The server encountered an internal error or misconfiguration and was unable to complete your request.
Apache/2.2.15 (Red Hat) server is used here.
Why I am facing this problem? Is root is automatically getting changed from public_html/ folder?
EDIT:
Directory Structure:
Username
.gnome2 (there are empty folders inside it)
.mozilla (there are empty folders inside it)
public_html (I have put css, fonts, js, etc folders and .htaccess, contact.html, index.html, etc files here.)
.bash_logout
.bash_profile
.bashrc
Username folder is under universitynameuniverse folder (whose other folders I cannot see).
Try this code in your .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
That’s it! You can now link pages inside the HTML document without needing to add the extension of the page.
Try this:
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule !.*\.html$ %{REQUEST_FILENAME}.html [QSA,L]
</IfModule>
## Results
# ~user/contact => ~user/contact.html (only if file exists)
It only works if the ~user/ directory actually exists on the filesystem.
If you need an external redirect instead, append an R flag to the RewriteRule directive.
The problem with your rewrite rule is that it's appending a .html suffix to the whole %{REQUEST_URI} variable which will probably result in a 404.
Update
Re-reading your question I noted that you want to map the ~user part to somewhere out of the apache webroot. In this case, try this:
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} ^/~(.+)/(.+)$
RewriteCond /home/%1/public_html/%2.html -f
RewriteRule . /home/%1/public_html/%2.html [QSA,L]
</IfModule>
## Results
# ~user/contact => /home/user/public_html/contact.html (only if file exists)

Apache RewriteRule pattern

I writing an .htaccess file for the web resources management.
I would like to this pattern of URI to use for static resource
^.*/web-console/static/(.*)$
And, my RewriteRule is below.
RewriteRule "^.*/web-console/static/(.*)$" "resources/floworks-web-console-1.0/static/$1" [L]
And, I request below URI
http://myhost/shop/web-console/static/css/default.css
But the Apache server hasn't match URI.
And if I delete "/web-console" Apache works fine.
Below is the RewriteRule
RewriteRule "^.*/static/(.*)$" "resources/floworks-web-console-1.0/static/$1" [L]
What is a problem?
Appendix
this is my directory structure
web base - /data/web
site base - /data/web/shop
htaccess - /data/web/shop/.htaccess
router script - /data/web/shop/route.php
static resources - /data/web/shop/resources/floworks-web-console-1.0/static
css file - /data/web/shop/resources/floworks-web-console-1.0/static/css/default.css
So, I wish response static resources if URI is started /shop/web-console/static
And, other case is pass to router script using "RewriteRule .* route.php [L]"
You should be able to do it like this. If you have this .htaccess in a sub folder shop, you should add rewritebase.
RewriteEngine On
RewriteBase /shop/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule "^web-console/static/(.*)$" "resources/floworks-web-console-1.0/static/$1" [L]
I found myself.
RewriteRule "web-console/static/(.*)$" "resources/floworks-web-console-1.0/static/$1" [END]
I'd change that flag from L to END
Thanks.

How would I go about creating a mod_rewrite that redirects to launch.php?i=/the/url/that/they/want?

So if the user types mydomain.com/dashboard, the document the server actually sends them is /launch.php?i=/dashboard.
The one caveat is that I would like to leave requests for
/flags
/people
/posters
/css
/icons
/images
/libraries
/patterns
alone, and they should request the actual folder.
How would I create such a mod_rewrite?
This is the .htaccess file for the CakePHP Framework.
Please replace the index.php and ?url= to fit your needs.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
The "!-d" tells Apache to follow existing folders and "!-f" to follow existing files.
Everything else is channelled through index.php
As suggested in a comment, you have to be aware that if it's not working it could be because mod_rewrite is not enabled and you'll not get an error stating that fact, you'll probably only have a HTTP 404.