I have a list of PDF [myfile.pdf] files on a folder/dir called example.com/uploaded/downloads/
I need a user to download or view on the page a pdf file, however I do not want them to see the uploaded on the url, which is the best way to do it?
so users can click a link example.com/downloads/
I had a .htaccess code (since im not good at it) it got me no where
RewriteRule ^downloads/([A-Za-z0-9-]+) /uploaded/downloads/$1 [L]
I have tried PHP header('... application/pdf'); not good either.
PLEASE NOT: example.com could change directory aswell e.g. example.com/new_design/ therefore the dir would be example.com/new_design/uploaded/downloads/ and users should be able to see example.com/new_design/downloads/
TIA
Make sure you have the RewriteEngine turned on and try this slightly modified pattern.
RewriteEngine on
RewriteBase /
RewriteRule ^downloads/(.*)$ uploaded/downloads/$1 [L]
If you are still having trouble, try looking at the Apache log files. They may indicate a problem with permissions or the file path. The log file is usually located in /var/log/apache2.
Related
I've been having some issues with my wordpress theme, i recently created a new theme and tried using it in my wordpress site, but i discovered that the css isn't loading. The css loads properly in my localhost and i didn't make any changes before uploading to the server,but after i uploaded it to the server, my css stopped working. I've never experienced this before and I'm 100% sure my header.php and functions.php file are correct. I checked with chrome dev tools to see if my css is loading, and it loads correctly.
I can see my css files showing in the head section in chrome dev tools, but my website page isn't displaying with the styles. Please what do I do? Also, i used wordpress 5.4.2 in my online server, but i used wordpress 5.3.4 in my local machine, does this affect anything
Looking at your website, your css files are all 404s. So the issue appears to be your server and not in WordPress. Please ssh/ftp/etc into your server and verify the files exist and have the correct permissions and ownership. In other words, could be a number of things wrong with your server, but the first things to look at are:
Do the files exist on the server in the correct location?
Do the files have 644 permissions?
Do the files have the correct owner? (I.e. if you uploaded as root, root owner should be the owner of the new files. Works fine if the files already existed, uploading as root (typically) won't change this, but if they're new they'll default to the logged in user).
Check your .htaccess, remove folders and just have index.php inside of it.
By folders I mean if it says eg. /new/index.php, just leave /index.php, and also check rewrite base.
You should have something like this
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
You should also check your urls in wp_options in database.
If it says http://localhost/your-project/ then you need to replace it with your current url of the project that is remote.
I think you need to flash your permalink. Just go to setting>permalinks and hit save button. I hope your css file will work fine after flush your permalink.
Thanks
I've got a CMS which I created by myself and I have an external link, which shows the web created by the user.
The link is: http://localhost/CMS/www/users_template/{user_name}
Is there any possibility to change the link and make it:
http://localhost/CMS/{user_name}
but it should still show the web page without any errors?
I think I should edit my .htaccess file, but no idea how to do it. I have never edited the .htaccess file before.
This is a duplicate.
Please view .htaccess: removing part of url path and stay at base
RewriteEngine On
RewriteBase /CMS/
RewriteRule ^www/users_template/(.*)$ $1 [L,R=301,QSA]
i'm using mod_rewrite to rewrite sites like "url.com/foo" to "url.com/index.php?site=foo".
The Code:
RewriteEngine On
RewriteBase /
RewriteRule ^([0-9a-zA-Z]+)$ index.php?site=$1
If i click on a link with href="/foo" it will give me
http://url.com/foo/?site=foo
The code works at other sites on the same V-Server, i have Boilerplate installed, BUT i dont use the .htaccess of it right now to fix the mod_rewrite, so it cant be a boilerplate issue, or?
I also tried the following code:
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ index.php?site=$1
That code, at least, rewrites to index.php?site=foo
BUT it still creates url's like the upper example with the unnecessary folder between.
Edit: to make sure everyone understands the overall idea:
The files are based in http://url.com (index.php, .htaccess) , so i set the RewriteBase to "/".
It should take links like
http://url.com/foo
and rewrite them to
http://url.com/index.php?site=foo
there are no folders included.
I solved it, damn i'm so stupid ;)
I have a folder called url.com/foo/ and the link im redirecting is url.com/foo to url.com/index.php?site=foo so it is always trying to get into that folder. Since i renamed the folder it is working very well.
I have been getting a similar error message on RewriteRule
pcfg_openfile: unable to check htaccess file, ensure it is readable
I also have the subfolder name similar to the redirected URL part but renaming it did not solve the problem (as suggested by Chris).
After multiple attempts, the problem was solved by updating the subfolder permissions to 755 (using cPanel folder permissions dialog) :
User: Read, Write, Execute
Group: Read, Execute
World: Read, Execute
PS: I am not sure if renaming the subfolder was actually required for this scenario since before and after the rename, error message was same.
I'm wanting to upload a standard php file to the root of my website which also has WordPress installed. I think there is something with the .htaccess file that's not letting me access a file even if it exists but instead passing every call through to WordPress's index.php file which in turn throws me to a WordPress 'page can't be found'.
I've looked through similar questions on here with no avail.
What I'm thinking is there is something funky going on, or I need to modify my .htaccess from the standard one that ships with WordPress or ??
Any help is appreciated!!
Thanks in advance,
Mark
If your file is called foo.php, add this line to your .htaccess file, directly below RewriteEngine on:
RewriteRule ^foo.php$ - [L]
Add a RewriteCond with the name of the file you want to access, that checks if the current file is the file that you want to access.
I have a PHP web app located on shared hosting.
My goal is to modify .htaccess file from PHP code when the PHP page is running.
I need that .htaccess to insert a couple of mod_rewrite lines into it.
The problem is that on Windows+Apache I can dynamically modify .htaccess file
but the same code on Linux reports a problem when I try to access this file in any
way (copy or fopen):
"failed to open stream: Permission denied"
I have given .htaccess file 777 permissions - still no result.
WHat prevents me from doing this? How can I develop a workaround?
P.S.
My initial goal was to be able to add a new RewriteRule into .htaccess that maps a
newly added category_id with new category_name.
If it wasn't shared hosting, I would use something like RewriteMap (in main Apache config) and would be able to access the map file.
This is the first real limitation I've been unable to tackle with PHP+Apache, but I hope it's circuventable too.
This seems like an overly-complex solution to just having a general "load category" page that takes the category name from the URL and loads the corresponding ID.
For example, if the URL is:
http://yoursite.com/category/programming
I would remap that to something like:
http://yoursite.com/category.php?name=programming
I want to suggest something else that also works. Instead of writing a rule for every 'special' url, why not use one for all?
I found it a whole lot easier to use what wordpress uses: every url is redirected to the index.
All you have to do is, set up the index file, read in the directory that was loaded (perhaps using $_SERVER['URI_REQUEST']), and deal with it.
add to .htaccess this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Thanks to that chunck you have a system somewhat unlimited at your disposal. If you ever feel like renaming you categrory url, or add another special case, it's already ready!
You only need a small set of rewrite rules. To do what Chad suggests:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/category/.*$ category.php [QSA]
Thus, anytime someone navigates to /category/category_id, the request will be directed to category.php, which will be handed the /category/ URI in $_SERVER['REQUEST_URI'], from which you can easily get the category ID, and you don't need to bother with editing the .htaccess file every time you add a category.
While I agree with the above comments, it can definitely be done. PHP apps like WordPress do exactly this based on changes made on the settings page. It should be as simple as writing the file out however the parent directory NEEDS to have permission for the web server user to write to it.
If it isn't working for you the trick will be making the parent directory either 777 or 775 and having the group set to whatever group Apache runs under (usually "apache" or "www" or something similar)
Adam (commented on your question) is quite correct though, some other security layer on your server might be preventing you from doing this, and this is probably a good indication that you might be approaching the problem the wrong way.
I agree with Chad Birch. In case you can't be dissuaded, though, in your situation I would first be looking for parent directories with locked-down permissions.
FYI, one of the reasons that rewriting the .htaccess is a bad idea is that any requests that come in while the .htaccess is being rewritten will not have any of your redirects applied.