htmlpurifier add missing url protocol - htmlpurifier

using AutoFormat.Linkify HTMLpurifier converts text such as http://www.example.com into links.
But many people write links without the protocol, such as www.example.com or example.com. Is there anyway to use HTMLpurifier to also convert these into links?

I know no way to get HTMLpurifier do this. But you should get this work by adding http:// to every link, that does not containing it. you can use a regular expression to do this.
preg_replace( '#\s((https?|ftp)\:\/\/)?([a-z0-9-.]*)\.([a-z]{2,4})\s#',
' http://${3}.${4} ', $html );
Test the regex here.
Example:
test example.com test<br>
test www.example.com test<br>
test http://example.com test
becomes
test http://example.com test
test http://www.example.com test
test http://example.com test
Now HTMLpurifier should do the right things.

Related

Google Cloud App Engine redirect all /*.html endings to /?

I have a lot of backlinks on the internet containing a .html ending. E.g. https://mywebsite.de/blog.html
But all my sites are served as https://mywebsite.de/blog in the meanwhile.
I use a Flask backend and found no solution to redirect those .html endings to /.
Is there a possibility to use the app.yaml configuration file for that?
Maybe something like:
handlers:
- url: /*.html
{define here the redirect}
I found nothing helpful in the documentation with regards to it. https://cloud.google.com/appengine/docs/standard/python/config/appref?hl=de#handlers_element
You'll need to do this within Flask. I see two main options.
(1) You could create Flask route that matches using a regular expression. You then match all routes ending in .html and do the redirect.
(2) Use #app.before_request on a function, check to see if request.url ends in .html and then redirect.
Note that redirect in Flask is a 302 by default and you probably want to specify a 301 redirect.
As gaefan suggested I solved the issue with Flask itself. My solution looks like the following:
#app.route('/blog/<slug>.html')
def html_redirect(slug):
return redirect(f"https://mywebsite.de/blog/{slug}" ,code=301)
Attention: this only redirect for subsites of /blog. Not just anything containing a ".html" ending.

hash tag is not removing from url AngularJS

I am creating a static site using angular 1. I done routing with ui-router.
Now I want to remove # tag from the url.
I googled it and got solution to enable html5 mode.
I done it as below:
app.config(function($locationProvider){
$locationProvider.html5mode= true;
})
and in index.html is added <base href="/"> but its not working.
and when i hitt localhost/myapp/ its showing Internal server error.
Please help me how to fix it.
Once you enable html5mode, you will need to rewrite your server.
Without html5mode, your browser would be making a request to http://localhost/ when the URL bar read http://localhost/#/myapp/ (because the browser doesn't send anything after the # symbol).
With html5mode, now that the # symbol is gone, the browser is making a request to http://localhost/myapp/, which your server may not be configured to handle.
Here's a resource that might help you out: https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-configure-your-server-to-work-with-html5mode

Apache and Yeoman built NodeJS app on the Same Server... Virtual Hosts?

I've been trying to add a NodeJS app (built by Yeoman - angular-fullstack generator) on my apache server.
I've found this other answered question : Apache and Node.js on the Same Server
suggesting to use ProxyPass like this :
ProxyPass /node http://localhost:8000/
The problem I encounter when I do that is that my app starts on an index.html wich includes some files with href.
Since these hrefs doesn't start like this
href="/node/..."
They aren't redirected by Proxypass, and thus result in a 404 error.
I can't just change all the hrefs : that would mean I need to do it all over again on my 3 environment : development, production and test, and even if I did that, everytime I'll use Grunt to test my app, it automatically rebuild my index.html anyway. (Besides, it doesn't solve everything, there are some problems with socketio appearing when I do that)
Only thing I can do then is using ProxyPass like this :
ProxyPass / http://localhost:8000/
There it does works, absolutely no problem, just like if I actually was using the app on from my server on localhost.
The only remaining problem is that I need to have 2 environments on my server, on for production and on for tests, and I just can't do
ProxyPass / http://localhost:8000/
ProxyPass / http://localhost:8001/
It obviously won't work since everything will be redirected to port 8000 bvefore anything can reach the second line.
So, I'm left with only two options :
Either find another solution than using "/" as criterion for redirecting to localhost:8000 that would work in the same manner (and I didn't find anything working)
Or use virtual hosts... And there goes another problem : I'm really not confortable with network issues, from what I understood, to have several virtual hosts on the same machine, I need several CNAMES (one for each virtual hosts), but I don't know how to list / add CNAMES (my server runs on Windows Server 2008 with no access to the world wide web), and I don't have any "DNS" application in my "Administrative Tools" as I'm supposed to according to this : https://technet.microsoft.com/en-gb/library/cc753579.aspx
Any help would be very welcome
Thanks in advance !
EDIT : I really think that my solution is to twitch my Apache configuration. Can anyone used to deal with server configs help me? :/
Seems like all I was missing was a
<base href="/node/">
tag (didn't even know about it, and Yeoman created it as )
I still have a problem though :
Socket.io ... I don't really get my own problem here : it's in node_modules (wich is normal since I need it in my server and my client), but trying to include it as I was doing so before using base href fails.
I don't even get how it did work before : (index.html : )
<script src="socket.io-client/socket.io.js"></script>
This doesn't seem right knowing my project folder is like this :
[PROJECT ROOT]
-client
--index.html
-node_modules
--socket.io-client
---socket.io.js

Angular js Passport example is not working

I am trying to follow this example:
source : https://github.com/DaftMonk/angular-passport
demo website: http://angular-passport.herokuapp.com/
I copied and pasted to my app and server almost same.
Routes work (in server side and client side too)
When I tried to log in or sign up I get a 404 error from server.
here is my server-side routes part.
I checked app.get('/robots.txt') works.
and this is routes part for login (that gave me 404 error):
app.post('/auth/session', session.login);
but I tried:
app.post('/auth/session', function(req,res){
console.log('here is session requested');
res.sendfile('robots.txt');
});
This code for checking whether server does respond well.
But still I got 404 error.
How can I fix this works? Ir how can I test this post routings with console.log or, something else?
Try using postman chrome extension for debugging RESTful api s
https://chrome.google.com/webstore/detail/postman-rest-client/fdmmgilgnpjigdojojpjoooidkmcomcm?hl=en
I think your issue may just be a simple path adjustment - sendFile requires a full path to be defined (you have provided a relative path by just using the filename) - try this:
res.sendFile('robots.txt', { root: __dirname + '/' });
Note that res.sendfile (lowercase 'f') has been deprecated and replaced with res.sendFile in Express 4.

Backbone routes break on refresh with Yeoman

I am building an app with Backbone and Yeoman. I am having an issue with the routing.
I have the following routes set up:
'test' : testMethod,
'' : index
I have set up pushstate:
Backbone.history.start({pushState: true});
I am using Chrome
If enter myApp.com#test the url changes to myApp.com/test and testMethod() fires correctly.
However if I try goto myApp.com/test directly or refresh after the browser has changed the url from # to / then I get a 404.
I am using the Yeoman built in server to test the pages. Could this be causing the issue?
I am not sure if you are using BBB within Yeoman. If you are, this should not be an issue. If you are not using BBB, this is a known issue. BBB has it's rewrite rules setup correctly to use pushstate, but yeoman's built in server does not seem to adopt this. You could edit your grunt.js file with your own rewrite rules to get pushstate working correctly. Some of the users in the above mentioned link have done this successfully.
When your app goes live, you will either need to serve those urls through your server or edit your rewrite rules to do the same. If the latter, and your application relies on SEO, SEO will suffer greatly.

Resources