Mnaouar Marouane
Mnaouar Marouane

Reputation: 31

How can I change the URL path to folder in server using htaccess

I want to change the URL path to a folder using .htaccess like the format below:

http://example.com/src/home/

To

http://example.com/home/

Any Help ?

Upvotes: 0

Views: 1589

Answers (2)

Ulrik McArdle
Ulrik McArdle

Reputation: 664

If I should design the structure, I would do it like this:

/
/src/
/src/public/assets/css/all.css
/src/public/assets/js/all.js
/src/public/index.php
/src/public/.htaccess
/src/app/ <= All you classes, php files and functions 

Set documentRoot to /src/public

Your index.php is now your entry point and you can load all your classes, setup a MVC pattern or anything you like.

All files that you use in your project in referenced by the server root / all assets that the browser is supposed to use, like css and js you put those in the public.

If you want you images to be secure, you could load them via a php file that takes them from outside the public folder.

Hope this all makes sense?

Upvotes: 0

Jerry U
Jerry U

Reputation: 638

Using .htaccess:

RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^home/(.*)$ src/home/$1 [QSA,L]

Upvotes: 3

Related Questions