htaccess - how can I add header set to a specific folder? - .htaccess

I would like to add a speicifc header set to a folder on my website
So i case my URL is as follow:
/kr/example.html
What should be the syntax?

Related

.htaccess rewrite rule to append the date to the filename, using Content-Disposition header

I am trying to download different file types like PDF, XLS, .jpg, .png, etc. directly from Joomla CMS via web browser. Documents and files like Word, Excel, Powerpoint, PDFs, .jpg, .png and text are stored in Joomla DOCman and when a user wants a file they click a link in DOCman menu in the website and the file is getting downloaded. I would like to get the date appended to the file name, when users download files like PDF, XLS, .jpg, .png, etc. from the website menu created. It loos like this is possible at server level using a htaccess rewrite rule, as the filename the browsers uses to save a file is included in the Content-Disposition header:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition
Is it possible to rewrite that header to append the date to the downloaded filename? I tried the below code in htaccess file for PDF file type, but it doesn't work as expected.
RewriteEngine On
RewriteRule [^/]+\.pdf$ - [E=FILENAME:$0]
<FilesMatch "\.(?i:pdf)$">
Header set Content-Type application/octet-stream
Header set Content-Disposition "attachment; filename=%{FILENAME-.date('Y-m-d').}e"
</FilesMatch>
Any help to get the correct htaccess rewrite rule to accomplish the above, would be higly appreciated.
Yes it is possible. This was tested and works.
RewriteEngine On
RewriteRule ([^/]+)\.pdf$ - [E=FILENAME:$1]
<FilesMatch "\.(?i:pdf)$">
Header set Content-Type application/octet-stream
Header onsuccess set Content-Disposition "expr=attachment; filename=\"%{ENV:FILENAME}-%{TIME_YEAR}-%{TIME_MON}-%{TIME_DAY}\.pdf\"" env=FILENAME
</FilesMatch>
The Apache documentation for the Header directive shows that the %{VARNAME}e format specifier should be used for placing environment variables in the Header value. However, since the value is provided via an ap_expr expression in my code sample, the ap_expr function env (or maybe reqenv) should be used instead. The Header directive documentation says that within ap_expr expressions:
Function calls use the %{funcname:arg} syntax rather than funcname(arg).

i want a URL rewriting for my URL using only .htaccess file

My URL is
http://127.0.0.1/public_html/organisation/home/index.php?page=Your-Profile
but i want my url looks like this using .htaccess only:-
http://127.0.0.1/public_html/organisation/home/Your-Profile
i want to remove using .htaccess file index.php?page=
Please Help Me..
You can remove the /index.php as this is assumed/set by default by the engine, but you can't remove the ?page= as this is a query parameter, not part of the 'url' as you are thinking it. So it would look like http://127.0.0.1/public_html/organisation/home?page=Your-Profile
If you're using wordpress then there is an option in admin to set 'pretty urls' which would achieve this through other means.

hide (:any) from url using htaccess

I am using CodeIgniter. I want to hide the last segment from the URL. My URL is given below:
http://localhost/metropolitan/admin/home/1
I create this URL using "routes.php:, which looks like this:
$route['home/(:any)'] = 'home/content/$1';
Can anyone tell me how I can hide the last segment from the URL? Is there any method using the ".htaccess" file?

Prestashop products url ends .html

In Prestashop I using SEO & URL and in settings on the "route to products" looks like this: {id}-{rewrite}.html and my url looks like:
www.example/12-product1.html
And if i delete from "route to products" .html my url open like this:
www.example/12-product1
But now the site not found. How I understand, now I need to change the URL without .html end in database?
If you delete the .html of the product rewrite rule it will conflict with the default category rewrite. To avoid this, change the category rewrite, maybe adding another - between id and the name.

Dynamic .htaccess using the url name

In a page
http://example.com/alum/
there is a link to the file
http://example.com/1.pdf
But I want to redirect to alum.pdf, using the url name in the name of the file
the same with /teac/ (for example) I want to redirec to to teac.pdf not to 1.pdf
How can I do it?
thanks!

Resources