I have added a sonata admin to my website.
In local, i can access to the path /admin but not when I push it on my prod environnement. I get a 404 when i try to access it :
Not Found
The requested URL /admin was not found on this server.
I have removed my cache in var/cache/prod
In case heres the content of my sonata_admin.yaml which is used :
_sonata_admin:
resource: .
type: sonata_admin
prefix: /admin
admin_area:
resource: "#SonataAdminBundle/Resources/config/routing/sonata_admin.xml"
prefix: /admin
sonata_user_admin_security:
resource: '#SonataUserBundle/Resources/config/routing/admin_security.xml'
prefix: /admin
sonata_user_admin_resetting:
resource: '#SonataUserBundle/Resources/config/routing/admin_resetting.xml'
prefix: /admin/resetting
Do I have to configure something, to access these paths on my server ? Or does this has anything to do with the .htaccess file.
Any clue of what might be causing this problem ?
Thank you in advance for your help !
UPDATE : Heres what I have when I do debug:router command on my localhost (can't do it in production)
D:\website>php bin/console debug:router
------------------------------------------ ---------- -------- ------ ----------------------------------------------------
Name Method Scheme Host Path
------------------------------------------ ---------- -------- ------ ----------------------------------------------------
homepage ANY ANY ANY /
_twig_error_test ANY ANY ANY /_error/{code}.{_format}
_wdt ANY ANY ANY /_wdt/{token}
_profiler_home ANY ANY ANY /_profiler/
_profiler_search ANY ANY ANY /_profiler/search
_profiler_search_bar ANY ANY ANY /_profiler/search_bar
_profiler_phpinfo ANY ANY ANY /_profiler/phpinfo
_profiler_search_results ANY ANY ANY /_profiler/{token}/search/results
_profiler_open_file ANY ANY ANY /_profiler/open
_profiler ANY ANY ANY /_profiler/{token}
_profiler_router ANY ANY ANY /_profiler/{token}/router
_profiler_exception ANY ANY ANY /_profiler/{token}/exception
_profiler_exception_css ANY ANY ANY /_profiler/{token}/exception.css
webhook_index ANY ANY ANY /mailchimp/webhook/endpoint
admin_app_event_list ANY ANY ANY /admin/app/event/list
admin_app_event_create ANY ANY ANY /admin/app/event/create
admin_app_event_batch ANY ANY ANY /admin/app/event/batch
admin_app_event_edit ANY ANY ANY /admin/app/event/{id}/edit
admin_app_event_delete ANY ANY ANY /admin/app/event/{id}/delete
admin_app_event_show ANY ANY ANY /admin/app/event/{id}/show
admin_app_event_export ANY ANY ANY /admin/app/event/export
admin_sonata_user_user_list ANY ANY ANY /admin/sonata/user/user/list
admin_sonata_user_user_create ANY ANY ANY /admin/sonata/user/user/create
admin_sonata_user_user_batch ANY ANY ANY /admin/sonata/user/user/batch
admin_sonata_user_user_edit ANY ANY ANY /admin/sonata/user/user/{id}/edit
admin_sonata_user_user_delete ANY ANY ANY /admin/sonata/user/user/{id}/delete
admin_sonata_user_user_show ANY ANY ANY /admin/sonata/user/user/{id}/show
admin_sonata_user_user_export ANY ANY ANY /admin/sonata/user/user/export
admin_sonata_user_group_list ANY ANY ANY /admin/sonata/user/group/list
admin_sonata_user_group_create ANY ANY ANY /admin/sonata/user/group/create
admin_sonata_user_group_batch ANY ANY ANY /admin/sonata/user/group/batch
admin_sonata_user_group_edit ANY ANY ANY /admin/sonata/user/group/{id}/edit
admin_sonata_user_group_delete ANY ANY ANY /admin/sonata/user/group/{id}/delete
admin_sonata_user_group_show ANY ANY ANY /admin/sonata/user/group/{id}/show
admin_sonata_user_group_export ANY ANY ANY /admin/sonata/user/group/export
sonata_admin_redirect ANY ANY ANY /admin/
sonata_admin_dashboard ANY ANY ANY /admin/dashboard
sonata_admin_retrieve_form_element ANY ANY ANY /admin/core/get-form-field-element
sonata_admin_append_form_element ANY ANY ANY /admin/core/append-form-field-element
sonata_admin_short_object_information ANY ANY ANY /admin/core/get-short-object-description.{_format}
sonata_admin_set_object_field_value ANY ANY ANY /admin/core/set-object-field-value
sonata_admin_search ANY ANY ANY /admin/search
sonata_admin_retrieve_autocomplete_items ANY ANY ANY /admin/core/get-autocomplete-items
sonata_user_admin_security_login ANY ANY ANY /admin/login
sonata_user_admin_security_check POST ANY ANY /admin/login_check
sonata_user_admin_security_logout ANY ANY ANY /admin/logout
sonata_user_admin_resetting_request GET ANY ANY /admin/resetting/request
sonata_user_admin_resetting_send_email POST ANY ANY /admin/resetting/send-email
sonata_user_admin_resetting_check_email GET ANY ANY /admin/resetting/check-email
sonata_user_admin_resetting_reset GET|POST ANY ANY /admin/resetting/reset/{token}
------------------------------------------ ---------- -------- ------ ----------------------------------------------------
Found the solution :
In Symfony 4.x, we need to specify a specific rewrite rule.
I followed the Symfony 4 documentation.
I just needed to do this command to fix it :
composer require symfony/apache-pack
You can also just add this code in a .htaccess file in the public sub-directory of your Symfony project :
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /index.php/
</IfModule>
</IfModule>
And voilà ! /admin and all subpaths are now accessible on the server.
Related
I have a WordPress website (mywebsite.com) running on a shared hosting server. Alongside, I made a node.js app running in the backend on port 3000, which has been programmed to have different API endpoints.
I would like to have the endpoints to be in the same domain as the website in specific URLs.
The main endpoint, which has been declared in the node.js selector environment, works just fine. Let's call it mywebsite.com/myapp.
The other endpoints (which have been declared in the express routes) work correctly outside the website environment but are instead caught by apache/wordpress if I try to access them on the same domain even as sub-uri.
For example, if I try to access mywebsite.com/secondendpoint or mywebsite.com/myapp/thirdendpoint, the request gets caught by Wordpress which loads the 404 page.
Now, I understand that I have to instruct the apache server to redirect the requests to the above mentioned URL to the node.js app.
As long as I don't have access to the apache server, the only choice I have to tweak the .htaccess files.
When I created the node.js app, the virtual environment has been automatically set through a .htaccess file in its own subfolder in my website public folder, where my whole website is: /public_html/myapp . It uses Phusion Passenger to handle the virtual environment the app is running in.
# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION BEGIN
PassengerAppRoot "/home/user/apps/myapp"
PassengerBaseURI "/myapp"
PassengerNodejs "/home/user/nodevenv/apps/myapp/12/bin/node"
PassengerAppType node
PassengerStartupFile app.js
PassengerAppLogFile "/home/user/logs/myapp.log"
# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION END
The above code works just fine. I tried to add an Alias as suggested in some tutorial:
# DO NOT REMOVE OR MODIFY. CLOUDLINUX ENV VARS CONFIGURATION BEGIN
<IfModule Litespeed>
SetEnv Alias /secondendpoint /apps/secondendpoint
</IfModule>
# DO NOT REMOVE OR MODIFY. CLOUDLINUX ENV VARS CONFIGURATION END
In the root of /public_html/ I have the following .htaccess file
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^/secondendpoint/(.*)?$ http://127.0.0.1:3000/secondendpoint/$1 [P,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
No matter what I try, when I try to access mywebsite.com/secondendpoint, I always get the Wordpress 404 message.
What am I doing wrong?
I even tried to create a subfolder in /public_html/secondendpoint which actually does proxy the traffic, but I feel like this is not the right way to do it.
So, after a week of attempts, I found out that the syntax of the RewriteRule was indeed wrong for what I was trying to achieve.
RewriteRule ^/secondendpoint/(.*)?$ http://127.0.0.1:3000/secondendpoint/$1 [P,L]
The correct syntax is
RewriteRule ^secondendpoint(.*)$ http://127.0.0.1:3000/secondendpoint/$1 [P,L]
As shown in the comment of the .htaccess file "should only be modified via WordPress filters".
In fact is does automatically overwrites the rules I wrote every time it updates.
The right way to do it would be tweaking the internal WordPress WP_Rewrite
which I'm still trying to understand.
My best attempt has been adding to functions.php of my theme these lines:
function wpd_wtf_rewrite_rule() {
add_rewrite_rule(
'secondendpoint(.*)$',
'http://127.0.0.1:3000/secondendpoint$1',
'top'
);
}
add_action( 'init', 'wpd_wtf_rewrite_rule' );
These lines are being translated in
RewriteRule ^secondendpoint(.*)$ /http://127.0.0.1:3000/secondendpoint$1 [QSA,L]
and updated into the .htaccess file.
The slash in front of the target is an issue I don't know how to fix.
However, the generated .htaccess string does not proxy the requests resulting in errors from the API.
I have 3 php apps on one server. I cant modify any apache files. Haw can I set .htaccess to remove web/ folder from url?
192.168.45.54/app1/
192.168.45.54/app2/
192.168.45.54/app3/web - I want to change it to 192.168.45.54/app3/
On adress 192.168.45.54/app3/web/ everythink is working fine. But haw can I remove web/ from url?
I created .htaccess files:
RewriteEngine On
RewriteBase /app3
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ web/$1 [QSA,L]
But when I go to 192.168.45.54/app3/ in symfony log files I have fallowing error:
No route found for "GET /app3/"
I use Symfony in 3.4 version. I think that problem is in .htaccess located in /web directory... Haw to configure .htaccess corectly?
I can't create virtual host becouse I haven't access to the server...
You need to make the web/ directory the document root of your website. If you have direct access to the webserver’s virtual host configuration, change the document root to the following line and restart Apache:
DocumentRoot /path/to/symfony/web/
If you can’t modify the virtual host file directly, your hosting provider will usually give you the possibility to modify the document root through some kind of online tool.
I have a Laravel 5.0 project. When I enter wrong link on locahost, Laravel redirects me to custom error template, using this code on app\Exceptions\Handler.php.
protected $dontReport = [
HttpException::class,
ModelNotFoundException::class,
];
public function render($request, Exception $e)
{
if($this->isHttpException($e)){
switch ($e->getStatusCode()) {
case '404':
\Log::error($e);
return \Response::view('error');
break;
case '500':
\Log::error($exception);
return \Response::view('error');
break;
default:
return $this->renderHttpException($e);
break;
}
}
else
{
return parent::render($request, $e);
}
}
After moving my laravel project to shared Hosting (not Linux) site does not redirect me to custom error template (views/error.blade.php), while entering wrong address which does not exist in app/http/routes.php. I tried many solutions, configured .htaccess file, but did not get a result. Error.log is empty. Here is my .htaccess file:
AddHandler application/x-httpd-php54 .php
<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 also tried remove RewriteCond and RewriteRule lines. In this case I can get 404 error page, but it brings me problems:
1) Laravel will not recognize aliases, if exists. For example (www.site.com/news)
2) Laravel will not send post requests to another page, for example (www.site.com/post)
3) Laravel will not display custom error template (views/error.blade.php) if I type wrong address, which not exists in app/http/routes.php, For example (www.site.com/wrong)
For accessing site without public, I made some changes:
1) I moved all files from public_html, except public folder to applicaton folder. Then, moved files from public folder into public_html.
2) Little changes in index.php
before:
require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
after:
require __DIR__.'/application/bootstrap/autoload.php';
$app = require_once __DIR__.'/application/bootstrap/app.php';
My files structure in public_html:
application
app (inside application folder)
server.php (inside application folder)
.htaccess
index.php
I accidentally replaced laravel 5.0 handler.php to laravel 5.1 handler.php.
I edited protected $dontReport file.
before
protected $dontReport = [
HttpException::class,
ModelNotFoundException::class,
];
after
protected $dontReport = [
'Symfony\Component\HttpKernel\Exception\HttpException'
];
I have a serious problem about routing and envirenement or module in symfony 1.4,so I created three modules frontend , mobile and backend.
So in frontend and mobile module,I'm using almost the same routing :
//apps/frontend/config/routing.yml
home:
url: /home
param: { module: user, action: home }
homepage:
url: /
param: { module: content, action: index }
....
default_index:
url: /:module
param: { action: index }
default:
url: /:module/:action/*
mobile module :
//apps/mobile/config/routing.yml
home:
url: /home
param: { module: user, action: home }
homepage:
url: /
param: { module: sfGuardAuth, action: signin }
....
default_index:
url: /:module
param: { action: index }
default:
url: /:module/:action/*
I use the link to access to my site
mysite.com/ ==> frontend module(frontend.php)
mysite.com/mobile.php ==> mobile module(mobile.php)
The problem is when I access to mobile version to login page correctly but after login they redirect me to homepage of frontend module not to the home page of mobile module?
Remark :
when I use this link mysite.com/mobile_dev.php with dev env the mobile version works very fine!
Edit :
here is my htaccess :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(%2d|-)[^=]+$ [NC]
RewriteRule ^(.*) $1? [L]
</IfModule>
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
# uncomment the following line, if you are having trouble
# getting no_script_name to work
RewriteBase /
# we skip all files with .something
#RewriteCond %{REQUEST_URI} \..+$
#RewriteCond %{REQUEST_URI} !\.html$
#RewriteRule .* - [L]
# we check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
# no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
So when I change index.php to mobile.php the link mysite.com/mobile.phpgo directly to to mobile version homepage and all works fine...
So my issue now is how to edit my .htaccess to redirect me like this :
mysite.com/index.php or mysite.com/ redirect me to my site
mysite.com/mobile.php redirect me to mobile version
Edit2 :
I explain you,when I start with this link mysite.com/mobile.php so it redirect me to mobile apps to login page but when after login instead it go to my homepage the new request search default front controller and it point on index.php so that give me the homepage of frontend apps not the mobile apps!
So why symfony with mobile_dev.php keep in memory it all time that we are in mobile dev env and with mobile.phpit switch me from prod mobile env to frontend prod env in first redirection?
The sfGaurdModule redirects to route homepage after successful login. Your homepage route in both apps have a URL defined as /. So when you login to frontend or mobile you are redirected to http://mysite.com/.
As one URL can only describe one resource there is no way your web server can understand which application you want to use when it gets the URL http://mysite.com/. It looks into .htaccess and sees that it should treat this URL as referring to http://mysite.com/index.php (frontend application). That's why you get redirected to frontend all the time.
There is nothing you can do with .htaccess to change it as you will never be able to differentiate just the URL http://mysite.com/.
What you can do is:
either change the URL of the homepage for mobile app to e.g. /mobile_home and switch no_script_name to false for the mobile app
or overwrite the signin() function of the sfGuardAuth module so it will redirect to different pages based on the application you now use.
Either way remember to set no_script_name to false in one of your apps as it will always cause a problem if you don't do this.
As for the dev environment. It works because after login in dev you are never redirected to / but either to frontend_dev.php or mobile_dev.php so the server does not get confused.
Be careful, you cannot use 2 times no_script_name: true (for your frontend and mobile apps), only once if it's on the same domain/subdomain!
You may want to look into relative_url_root, I also had an issue with this: Symfony does not detect relative url root.
If you're using sfGuardPlugin or sfDoctrineGuardPlugin you have to check the plugin code to modify the redirect behavior. sf 1.4 have poor multiple app support. And just to clarify you have created three "apps" not three "modules", as you said.
There is something strange going on. I am using Zend Framework on a subfolder in a site. I have a modular structure to my website, so the links consist of module names (www.xx.com/modulename). I have created a .htaccess file for the root dir, so that all of the requests would be routed to the public dir.
When i try to access the homepage ( www.xx.com) or any module it all goes exactly as it should. www.xx.com/authentication, www.xx.com/sample or www.xx.com/deathmetalreallyrox are all working as they should. But when I try to connect to www.xx.com/admin, it crashes and BURNS!!!! It does work however with www.xx.com/public/admin/.
Could it be, that my Hosting provider has set up some sort of rule in the httpd.conf to prevent me from accessing the admin section in my hosting?
Here's my .htaccess:
SetEnv APPLICATION_ENV development
RewriteRule ^(browse|config).* - [L]
ErrorDocument 500 /error-docs/500.shtml
SetEnv CACHE_OFFSET 2678400
SetEnv APP_DOMAIN http://www.xx.com/public
SetEnv APP_PREF /public
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Expires "Fri, 25 Sep 2037 19:30:32 GMT"
Header unset ETag
FileETag None
</FilesMatch>
RewriteEngine On
RewriteRule ^(adm|statistics) - [L]
RewriteRule ^admin/(.*) public/admin/$1
RewriteRule ^(.*)$ public/$1 [L]
Help?
EDIT:
Browser error msg:
Not Found
The requested URL /admin/ was not found on this server.
You redirect anything starting with admin/ to public/admin/ first and then everything to public/whatever. So when you request /admin/, it's trying to give you /public/public/admin/, which doesn't exist, so you get a 404.
Try removing the line RewriteRule ^admin/(.*) public/admin/$1. It's already handled by the next line, and you don't want to do it twice.
It turned out, that the server was somehow configured wrongly.
As I do not have the total control over the server, I couldn't know, that there was a rule in the httpd.conf, that denied access to any folder named admin or administrator, so that when I tried to get the contents of a folder by this name, Apache first checked, if a folder by this name existed, and denied it by default.
So, the concise answer, the server was configured wrongly, didn't allow access to specific folders.