I'm implementing a RESTful service using Yii2 advanced template following this guide. However, I'm ended up getting the following structure for the REST service:
http://localhost/MyProject/api/web/v1/user/1 whereas it should be
http://localhost/MyProject/api/v1/user/1.
How can I remove the /web/ from the URL path?
If you use apache in .htaccess
<IfModule mod_rewrite.c>
#Send all /api requests to api/web folder
RewriteRule ^api/(.*)$ api/web/$1
</IfModule>
You add below code in web.php file...
'components' => [
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
],
],
And Then add one file .htaccess file in web folder..
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
I actually like to use Kartik's Practical App or Practical-A App. They are based on the yii2-advanced template, but with some changes, like getting rid of the /web directory
If you are going to host it on your own server, just create a virtual host pointing to the api/web and you will have it sorted.
Here is a sample
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName api.websiteurl.com
DocumentRoot /var/www/html/app/api/web
</VirtualHost>
With that, I can access my api from api.websiteurl.com
If you want to api to be accessed from websiteurl.com, then just set the document root of your server to point to api/web
Related
I use this package and it work properly on test websites but in app I got this Error
WebSocketException: Connection to 'https://socket.excopro.com:0/socket.io/?EIO=3&transport=websocket#' was not upgraded to websocket
and this is my Code
SocketService() {
var socket = io(
'https://socket.excopro.com:443/', <String, dynamic>{
'transports': ['websocket'],
'autoConnect': true,
});
socket.on('connect', (_) {
print('connect');
socket.emit('msg', 'test');
});
socket.on("connecting", (data) => print('connecting'));
socket.on('connect_error', (data) {
print(data);
socket.emit('msg', 'test');
});
}
I have met the same issue.
For my case, I use Nginx as proxy. I solve the issue by added some proxy header to my Nginx configuration.
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
You can refer to this link.
I ran into this error in my Flutter/Dart app which is being serviced by NGinx + NChan. It turned out that the wss:... url that I was creating in Dart was malformed - easily done if you are doing string interpolation in Dart, PHP and JS all within the space of a few minutes given that each language has its own way of interpreting interpolated variables in braces. The result was that location = ~ /path/(regex)$ setting in my Nginx/NChan conf was not recognizing the URL as one that required upgrading to wss. Nginx then proceeded to try and find the resource at https://example.com/malformed/path without upgrading it to wss which then threw up this error in Dart.
Lesson - when this happens check that the URL you are trying to reach is well formed so it ends up being recognized as one requring an upgrade to wssserver side.
You have make sure to enable websocket in Virtual Host.
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteCond %{HTTP:Connection} Upgrade [NC]
RewriteRule /(.*) ws://127.0.0.1:3055/$1 [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
RewriteRule /(.*) http://127.0.0.1:3055/$1 [P,L]
Here is the complete Virtual Host if anyone needs,
<VirtualHost *:80>
ServerName domain.com
ServerAlias www.domain.com
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
<Proxy *>
Require all granted
</Proxy>
ProxyPass / http://127.0.0.1:3055/
ProxyPassReverse / https://127.0.0.1:3055/
ProxyPass /api http://127.0.0.1:3055/api
ProxyPassReverse /api https://127.0.0.1:3055/api
RewriteEngine on
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteCond %{HTTP:Connection} Upgrade [NC]
RewriteRule /(.*) ws://127.0.0.1:3055/$1 [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
RewriteRule /(.*) http://127.0.0.1:3055/$1 [P,L]
RewriteCond %{SERVER_NAME} =domain.com [OR]
RewriteCond %{SERVER_NAME} =www.domain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
Received this error when there was a mismatch on the client and server versions of socket_io. Try finding the matching version to the version the server is using.
I had for the same error, this is what my environment:
VPS with docker
Azuracast as container
Nginx proxy manager as container
a public domain that point to the Azuracast via hots in nginx proxy manager.
a flutter/dart mobile app that stream the radio flux, and I wanted to get "Now playing audio" updates via Websocket.
I had the same error when trying to connect via https schema with/without port.
I finally found that in nginx proxy manager I have to activate the Websocket option in the host I created. Then changed my url to wss://... instead of https://...
In flutter I used this package for websocket => web_socket_channel: ^2.2.0
and this is the line of code to init the websocket:
var websocket = IOWebSocketChannel.connect(Uri.parse('wss://xxx.com/api/live/nowplaying/my_station_shortcode'))
I have a site https://example.net
to ensure that all users go to the https:// I set up a redirect with APACHE (on the default.conf) as followed:
<VirtualHost *:80>
ServerName example.net
Redirect permanent / https://emalsys.net
# DocumentRoot /var/www/example.net/
<VirtualHost *:80>
My issue is when I try to access my phpmyadmin example.net/phpmyadmin I redirect to https://example.net/phpmyadmin and the page cannot be displayed.
(It is obviously working if I remove the Redirect).
How can I get avoid the redirect only for my phpmyadmin?
Any idea?
This is what I use in my servers to force HTTPS
RewriteCond %{HTTPS} !=on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
For other examples see Apache's wiki https://wiki.apache.org/httpd/RewriteHTTPToHTTPS
You can enter a REWRITECOND before a rewriterule:
REWRITECOND %{REQUEST_URI} !^http://www.example.com/phpMyAdmin
REWRITERULE / https://emalsys.net
A way around:
I do not know why but if I type as url example.net/phpmyadmin I will be redirected to https://example.netphpmyadmin/ but if I write https://example.net/phpmyadmin/ (with the /)I go to php my admin.
No idea why but I hope it will be of help to others.
to force https:// on pyp myadmin I added: $cfg['ForceSSL'] = true; at the end of phpMyAdmin’s config.inc.php file (see http://thebarton.org/forcing-ssl-with-phpmyadmin/).
We recently forced all pages to be HTTPS through .htaccess:
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
The problem is that I get "Circular redirect path detected" from Facebook debugger because the original URL is https, but the og:url is http (so we don't lose all of our old likes), and then it gets a 302 loop back to https.
How can I make Facebook an exception to this .htaccess rule?
This question addresses the user-agent that facebook external hits will look like. You just need to add a condition to check for it:
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_USER_AGENT} !facebookexternalhit/[0-9]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Im using openfire for the xmpp to my website. I have done a server move and relocated the site on the same server as openfire as they were both on different servers before.
Since the move im getting error 500 on the /http-bind/ request on my website.
How can i debug this or what to i need to consider that may be causing the error 500 on /http-bind/
Error log
[warn] proxy: No protocol handler was valid for the URL /http-bind/. If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.
Short answer: You need to load the 'proxy_http' module in Apache.
There are some instructions I wrote in the Prosody documentation on setting up BOSH with Apache, but they should apply equally to any BOSH/XMPP server. In particular I'm not sure whether Openfire is fussy about /http-bind vs. /http-bind/. Therefore if the below instructions do not work, try adding the / to the end of the URL.
Summary
Run: sudo a2enmod rewrite proxy proxy_http
Add the following lines to your Apache config:
<Location /http-bind>
Order allow,deny
Allow from all
</Location>
RewriteEngine On
RewriteRule ^/http-bind$ http://example.com:5280/http-bind [P,L]
I would like to add that with a properly configured server you can just put this in your .htaccess in the root of your web folder:
<IfModule mod_rewrite.c>
RewriteEngine On
# Rule1
RewriteCond %{REQUEST_URI} ^/chat1/http-bind
RewriteRule ^.*$ http://chatsrv1.joynmenow.com:7070/http-bind/ [P,L]
# Rule 2
RewriteCond %{REQUEST_URI} ^/chat2/http-bind
RewriteRule ^.*$ http://chatsrv2.joynmenow.com:7070/http-bind/ [P,L]
</IfModule>
I'm not exactly sure what configs are required to allow this in a .htaccess however my godaddy VPS allowed me to do this in it's default configuration.
In apache configuration file (i.e., httpd.conf) we had virtual host configuration, which is working for last 2 years. Today to there no problem with it. But when I was asked to add redirection to it, it's not working. My virtualHost conatainer looks something like this
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName domain.com
Redirect 301 / http://www.domain.com/
Redirect 301 /index.html http://www.domain.com/
</VirtualHost>
Here when I'm typing "http://domain.com" it is taking to "http://www.domain.com" expected behaviour. But when I type "http://domain.com/index.html" or "http://www.domain.com/index.html" it is not taking me to "http://www.domain.com"...it is joomla website.
Can anyone resolve this for me...
Thanks in advance
Add
ServerAlias www.domain.com
in a new row after ServerName domain.com
It sounds like it's applying the first redirect before trying the second one.
Have you tried putting the Redirect lines in the other order?
Redirect 301 /index.html http://www.domain.com/
Redirect 301 / http://www.domain.com/
Usualy this is achieved by using a more general approach with mod_rewrite :
This code should be placed in the htaccess file in the root of your domain, i.e. domain.com/.htaccess
or the virtualhost configuration.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
</IfModule>
( e.g. also here Forcing the www prefix with PHP/htaccess/mod_rewrite )