How Remove a folder form url using .htacces - apache

I develop a new site for a client and I don't want to move to the root folder of the server.
Besides that, the hosting service do not alow me to change the physical path.
So I decide to use .htaccess to handle this.
My .htaccess file is like this:
AddHandler php56-script .php
suPHP_ConfigPath /home/balletpaulacastro/
Options +FollowSymLinks
RewriteEngine on
So when the user try to access www.balletpaulacastro.com.br they will be redirected to www.balletpaulacastro.com.br/bpc where the new site is located.
What i want is to rewrite the url to not show de /bpc/ folder.
I try many examples, but i'm not a coder, so if you guys can write down the entire code with my actual url and folders, that will be so nice.
Thanks in advance
Raul

Try :
RewriteEngine On
RewriteRule ^((?!bpc).*)$ /bpc/$1 [NC,L,QSA]
This will rewrite
example.com
to
example.com/bpc

Related

Access external files as local files with htaccess

I have a source and several user domains. I'm keeping JS, CSS and image files on the source domain and in the user domains I'm including those stuffs like source.com/js/jquery.js but I want to show them like user1.com/js/jquery.js, user2.com/js/jquery.js without the files physically there.
source.com/css/bootstrap.css
source.com/js/jquery.js
source.com/user/1/library/picture.png
source.com/user/2/library/picture.png
user1.com/css/bootstrap.css
user1.com/js/jquery.js
user1.com/library/picture.png
user2.com/css/bootstrap.css
user2.com/js/jquery.js
user2.com/library/picture.png
Is this possible with htaccess? And for helping, all of these source.com, user1.com, user2.com are in the same server.
Thanks for any help.
Okay, test this :
in user1.com .htaccess use RewriteRule
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^js/jquery.js$ http://source.com/js/jquery.js [P]
</IfModule>
then your url is something like this http://user1.com/js/jquery.js and file will be read from http://source.com/js/jquery.js without changing url.
This worked for me.

mod_rewrite inserting full path to file

I need to create a rewrite to take traffic going to mp3/mp4 files in a specific subdirectory and then route them to a PHP file that tracks download stats etc before routing them to the actual file location since iTunes requires your podcast RSS contain actual media file extensions (.mp3, .mp4, etc)
I have created rewrites before with no problem but now I am running into an odd issue on this company's server.
My .htaccess located at www.company.com/companytools/podcasts
RewriteEngine on
RewriteRule ^/(.*).mp3$ /test.php?file=$1 [r=301,L]
Right now it is partially working it does act upon the mp3 file but ends up including the full path to test.php after the domain, so I end up with a 404 page looking for this URL:
www.company.com/www/internal/docs/companytools/podcasts/test.php?file=test
basically I need the path, but only the /companytools/podcasts part.
Any help is appreciated.
You may not need R=301 here to hide actual PHP handler.
Try this rule with RewriteBase:
RewriteEngine on
RewriteBase /companytools/podcasts/
RewriteRule ^(.+?)\.mp3$ test.php?file=$1 [L,QSA]

read images from root directory in subdomain with htaccess

I have a domain like example.com where root directory is web.
I have created a subdomain happy.example.com where directory is outside web folder called happy and connected it to happy.example.com.
My webpage tree looks like
happy
web/images
So all my images for root directory are stored in (web/images)
example.com/images
So a full path to an image can be
example.com/images/me.png
Now i have created a sudbdomain which i call:
happy.example.com
What i would like to do is if i type
happy.example.com/images/me.png
then i should be able to see the picture.
So somehow i need to link all images folder to a subdomain from root directory in web.
I hope you guys got my question.
I guess i shoud have an htaccess file with all funny stuff in happy folder?
Cheerz
Since the two document roots of your two domains aren't connect to each other (one inside the other, or the same), you'll need to either redirect or proxy, or, use a script.
To redirect is easiest, but it'll change the URL in the browser's location bar:
Redirect 301 /images http://example.com/images
or using mod_rewrite:
RewriteEngine On
RewriteRule ^images/(.*)$ http://example.com/images/$1 [L,R=301]
To proxy, you need to have mod_proxy loaded, which isn't always the case if you're using a webhost or hosting service. But you can use the P flag in mod_rewrite to do this:
RewriteEngine On
RewriteRule ^images/(.*)$ http://example.com/images/$1 [L,P]
The last option is to route all image request to a script, like a php script or something. And the script itself returns the image:
RewriteEngine On
RewriteRule ^images/(.*)$ /load_image.php?image=$1 [L]
then you'd have something like:
<?php
header("Content-type: image/jpeg");
readfile('../web/images/' . $_GET['image']);
?>
Obviously, you'd need to check the extension and return the correct content type depending on the image type.

Rewrite rule in Apache/htaccess doesn't work

This is what is in my htaccess file which is located in the same directory as my php project:
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
I have got one link on my page that sends the user to this address:
http://localhost/PHPTest/index.php?article=27
This is the output that I want== index.php/article_27 ?
UPDATE:
When I press the link, this is the output in the url:
http://localhost/PHPTest/index.php?article=27
This should be intercepted in the .htaccess in my php project folder and swap it to this:
http://localhost/PHPTest/index.php/article_id_27
Here is my rewrite rule. But it doesnt work:
RewriteRule ^index.php?article=([0-9]+)$ index.php/article_id_$1
More information. There is my project path, where index php is:
C:\xampp\htdocs\PHPTest
The url doesnt display itself as index.php/article_27
Why would it? You're pointing the link to ...article=27 and your rule rewrites from ...article_27 to ...article=27.
In the scenario you have given, you probably want a redirect from ...article=27 to ...article_27, not a rewrite.

Redirect entire site except one directory to a new site - apache .htaccess

I am trying to move my current site over to a new domain, except for ONE directory.
Example:
current site: oldsite.olddomain.example
new site: newdomain.example
So I know I can create an .htaccess redirect entry to do this, and it works, but I want ONE exception - I do NOT want to redirect a specific directory. I still want this to work:
http://oldsite.olddmain.example/myspecialdirectory/… and every file and directory under it.
Can someone help?
Thanks!
Try this mod_rewrite rule in the .htaccess file in the document root of oldsite.olddomain.example:
RewriteEngine on
RewriteRule !^myspecialdirectory($|/) http://newdomain.example%{REQUEST_URI} [L,R=301]