Polymer: how to link to a PHP file? - polymer

I'm building a multi-page app using Polymer. In one of the components (or pages, really), I've got a link to a PHP file:
<p>Export as PDF</p>
This PHP file generates a PDF file. If I point the browser directly to it, it prompts me to save the PDF file - all good.
But when I click on the link form within Polymer, then it goes to my "page not found" component.
My .htaccess file redirects everything to Polymer's index.html, except files that do exist:
# Pass all requests not referring directly to files in the filesystem to index.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.html [L]
It actually works, since when I point the browser directly to the PHP file it executes it properly.
So, how do I tell Polymer to not treat this link as an internal router thing?
Thanks a lot for any assistance.

The solution was pretty simple, I just needed to use an absolute URL, rather than relative:
<p>Export as PDF</p>

Related

how to remove the url extension

I am developing a website for myself, pure and without server language.
The urls are as they are called in the a tag, for example: blog / index.html.
Is there anything I can use to change that? I don't want to have to use framework. I would like to know if there is any tool that does this.
What I want to change is the ending. I don't want the extension to appear, just the route
try create .htaccess file on your root folder then paste this
#remove html file extension-e.g. https://example.com/file.html will become https://example.com/file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]
you can read more about this here https://www.plothost.com/kb/how-to-remove-php-html-extensions-with-htaccess/
EDIT
Since you are using Vercel.com, as per their documentation there's a file config named vercel.json you can add this
{
"cleanUrls": true
}
the docs said,
When set to true, all HTML files and Serverless Functions will have their extension removed. When visiting a path that ends with the extension, a 308 response will redirect the client to the extensionless path.
for more information pls read their docs here https://vercel.com/docs/configuration#project/clean-urls

Pointing webserver to load .html page and not subdirectory index

So I have been searching for a few hours now and have not found the answer to my problem.
So I have a website that I was wanting to take the page extension off e.g. .html / .php etc.. and I had found that I could include the below code in the .htaccess file.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
I have now added that code and it works great for removing .html from my pages. However now I have come into a new problem. I have a page and directory both named 'guides' on the root of my public_html folder. Now when I enter the url 'www.mydomain.com/guides' the index of the guides directory is showing rather than the guides.html page that I am wanting to display.
I am wondering what would be the best way to get around this and make my server look for the webpage first rather than display the guides directory index.
I have been looking at RewriteRule's but it seems to be all wordpress content and does not work with my non wordpress website.
Any help would be appreciated, thanks.
The best solution is to change the name of the directory or the file to something different. RewriteRule can not rewrite a directory request to file as the directory request is first handled by mod-dir (directory module) .
If you do not want to change the name, then you can turn off DirectorySlash on your server using the following line in htaccess :
DirectorySlash off
https://httpd.apache.org/docs/2.4/mod/mod_dir.html#directoryslash

.htaccess file does not overwrite html and instead shows markup on page

I'm building a personal website, and I want my url links to look like domainname.com/example as opposed to domainname.com/example.html
I'm using fastcomet for my webhosting service. Under my public_html folder I have a .htaccess file. Here is the code for my .htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
</IfModule>
My .htaccess file and all my html, css, js files are under home/username/public_html/ and I've removed the .html extensions from all my html files. After I applied these changes, I tried to get http://domainname.com/example and I saw the html markup as opposed to the rendered html such as:
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml">
<all my code .... />
</html>
Any suggestions on what I should do? I am placing the .htaccess file in the wrong directory? I also tried with and without the Ifmodule tags on the .htaccess file.
Thanks!
Yes, indeed, you should keep the file extension .html so you can have your files properly handled and your .htaccess to work as intended. It seems that in the meantime, you have actually posted the ticket to our Tech Support Team. Though there has been a slight misunderstanding regarding your request, a senior member of our team successfully excluded the processing of HTML and HTM files from the NginX service and they are now passed directly to Apache for your domain. As a result, all of your url links now look like domainname.com/example as opposed to domainname.com/example.html. Should you have any further requests, do not hesitate to contact us back!
I've removed the .html extensions from all my html files
This is why you see page code.
Rename the files back and use the following rewrite rule:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [L,R=301]
</IfModule>
FastComet Team here! Part of our shared hosting environment is utilizing NginX as a reverse proxy to the Apache web service. This means that static content, such as HTML files, is processed directly by NginX and not by Apache. This is why any rules that you apply to the .htaccess file of your website are not making any actual changes. The requests to HTML files will be processed directly by NginX and they will not be passed to Apache so the .htaccess rules will be ignored.
There is an easy way of resolving that. We can exclude the processing of HTML and HTM files for your domain or even your entire hosting account. This way, those requests will be processed by the Apache web server, instead of NginX. In this case, the .htaccess rules that you apply will be taken into consideration by the system and they will work without any issues. To achieve that, simply submit a ticket to our Technical Support team and we would be happy to assist.

How to set .htaccess so link in side html file will read from a base directory

Right now, I have put my html files under public/views folder,
libraries under public/libs, and customized files in public/src
I am using the DictoryIndex to set the default home page. Like DirectoryIndex public/views/index.html
but inside the index.html file, I have to use to open the file under the same directory as the index.html, otherwise it could not find the file. And then the URL will look ugly, like site.com/public/views/product.html.
Can I ask, how could I set the .htaccess file to get rid of the public/views in the URL address?
One more question, when i write the code to import the libraries in index.html, it seems like it will read from the base folder (like where I put the .htaccess file). But in the other html files, they will read from their own directory, like the html file in public/view will start to read from folder views. Is there anyway to solve this problem?
Thank you
Do you need to access your libs and custom files through HTTP too? If not, just set your document root to public/views
Otherwise, you could rewrite *.html to public/views using something like
Options +FollowSymLinks -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule (.+\.html)$ /public/views/$1 [L]
Anyway, using a fullpath instead of just a filename in the DirectoryIndex directive is not a good idea, for obvious reasons.
It also solves your second issue. For now, public/views/index.html is considered as / so anything relative to this file is relative to /, not the views folder. On the other hand, any other file is still considered as "itself", therefore includes are relative to the views folder.

How do I redirect "website/page" to "website/page.html" when people type it in browser (pretty-url)

I recently started using a static site with godaddy.com without a cms. It's a basic website I uploaded and is only html/js/css.
When people type "website.com/page" they get 404 not found.
When they type "website.com/page.html" they get the correct page.
How can I fix my site so users can simply type "website/page" and not be forced to type "website/page.html" without using php?
SOLUTION
After researching the information about .htaccess files provided by #Gijsberts (thank you), I did the following:
Created a .htaccess file on server.
Added the following code:
# Remove the .html extension from html files
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.html [NC,L]
Most CMS systems have a .htaccess file what handles the redirect and the 404 errors. In CMS system they are most called "Pretty-urls". Read the links below to set up those pretty urls yourself with a static web page without a cms.
https://mediatemple.net/community/products/grid/204643080/how-do-i-redirect-my-site-using-a-htaccess-file
http://code.tutsplus.com/tutorials/using-htaccess-files-for-pretty-urls--net-6049
You normally can do this with your Webserver config. In Apache you have this enabled automatically. In nginx you should have a look at this tutorial.
If you are using caddy you have to config your caddyfile like
ext .html .htm .php
if you are using microsoft iis have a look at microsofts tutorial.
Let me know if you are using something else or need more help.
EDIT
If you are using a webspace you may are not able to change the config of the webserver. you now can use .htaccess. create a .htaccess file and write down something like
Options +MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]