htacccess redirect to separate folders - .htaccess

I have a record shop online.
The following URL example shows the product info page without a problem:
http://www.example.org/tp/html/product/33/record1.html
Im using an .htaccess file as follows:
RewriteEngine On
RewriteRule ^product/([0-9]+)/(.*).html$ detail.php?id=$1 [L]
My problem is that the sound files are in a different folder on the server to the detail.php file.
The mp3 sound files are not shown on the page as they are in a different folder.
How do i tell the .htaccess file to look in the ../../sf folder to find the mp3 files?
thanks!

Related

Redirect existing second page to non-existing url

I have a site https://sitename.com/web (example). So, full path to page is sitename.com/web/index.php. On ftp server there is folder /web which also contain second page file - index-2.php. How to avoid creating /web-2/ folder and redirect index-2.php to sitename.com/web-2 ?
Easy, create an .htaccess file inside the root folder of your site, then add the following lines to it:
RewriteEngine On
RewriteRule ^web-2$ index-2.php [QSA,L,NC]
This site might help you with htaccess:
https://www.htaccessredirect.net/
A nice tutorial on .htaccess files also below:
https://www.digitalocean.com/community/tutorials/how-to-use-the-htaccess-file

images,js, css not loaded when using htaccess

First what I want to note it for you is
I use appserv.
I create the .htaccess file in direct file, so .htaccess file is in the folder /web.
All I want is use RewriteRule for all web links except (.css)-(.js)-(all types of images and .txt)-(and all files name).
I use this code:
RewriteEngine On
RewriteRule ^content/([0-9]+)/$ content.php?pid=$1 [L]
but when I open this page as web/content/2, the css, js, images are not loaded.
I do not know what's the problem :(

Htaccess file to protect files on the server

I created a php script that allows you to download and upload files. Files are saved to a directory XXX. Can I add an htaccess file to protect files in this folder? I would want that people must login to my web site to download files. I would want that people who know the position of XXX can not download file without to login to control panel of my web site. What should I write in this htaccess file? The site is hosted. Files can have any extension.
You can do something like this in your htaccess:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^files/([^/]+)/([^/]+).zip /download.php?folder=$1&file=$2 [NC]
All requests to files/XXX/YYY.zip will be rewritten to files/download.php?folder=XXX&file=YYY and your php can handle the authentication.

htaccess rewrite not working beyond first directory

I have had to change the name of a page on my wordpress site. In the url structure the page has many sub pages which are illustrated as follows:
www.mysite.com/folder1/plus whatever else may come here
Basically I want to do a wildcard redirect where any URL matching the folder1 part of the URL gets caught and redirected to the following:
www.mysite.com/newfolder1/folder2/
The following redirect works for the above situation
RewriteRule ^folder1/?(.*) http://www.mysite.com/newfolder1/$1 [R=301,L]
But fails and give a 404 for the following
www.mysite.com/folder1/folder2/folder3
It will not redirect beyond the folder2 depth. Why is this?
Following up on the comments:
The problem sounds like the .htaccess file (or the rules you're talking about) is in the wrong location.
As far as my understanding goes, Apache reads all the .htaccess files (and other server configs that do redirects) from the "top" down - i.e., .htaccess files in subfolders are processed after .htaccess files in the root folder.

simple .htaccess rewrite URL to different directory on same server

Ok, I'm clueless here...
I need to rewrite a directory structure and all sub-directories within it to a directory within the same server, but a root that is before the directory.
For example:
http://www.mydomain.com/Themes/default/css/folder
and all directories called upon after folder. Such as folder/sub_folder or folder/afolder/anotherfolder, it needs to include ALL sub-directories within the folder directory.
should be redirected to this:
http://www.mydomain.com
How do I do this via a .htaccess file within the folder path http://www.mydomain.com/Themes/default/css/folder?
Please someone help.
Thanks guys :)
The files within the directory structure still need to be accessible for that structure when called via PHP, but I don't want people being able to browse to http://www.mydomain.com/Themes/default/css/folder and be shown all subdirectories within that folderpath and/or all files. Same thing for all sub-directories that follow that folder path.
I'd like to be able to place the .htaccess file within the http://www.mydomain.com/Themes/default/css/folder directory on the server, but don't know exactly what code to use for this.
ALSO, even more challenging... The domain name can change, so I'd rather not use the domain name within the .htaccess file, instead perhaps use .. or . to go up a directory or a different method of grabbing the domain name within the .htaccess file.
Create a .htaccess file in /Themes/default/css/folder and place these lines there (it requires mod_rewrite):
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ http://%{HTTP_HOST}/ [R=301,L]
It will redirect (301 Permanent Redirect) all requests to a folder to a homepage. If file is requested, it will allow it.
If you want to have it working for folders as well as files then remove the RewriteCond line -- it will redirect ALL requests (even for non-existing URLs) to a homepage.
If you will see "500 Internal Server Error" after creating such file, then it is your server configuration: mod_rewrite may not be enabled or it's directives (RewriteRule, RewriteCond, RewriteEngine) are not allowed to be placed in .htaccess. In any case -- check Apache's error log for exact error message (it will give you the exact reason).
http://www.besthostratings.com/articles/prevent-directory-listing.html
IndexIgnore *

Resources