1

I've made a web app, and left all of the pages (.php) in the root of the project folder. I now want to move every page from the project root folder into a /view folder.

Original URL Example: project/about-us

Original File: project/about-us.php

Desired URL: project/about-us

Original File Location: project/views/about-us.php

I have tried Hiding folder in URL using .htaccess but no luck as of yet.

My .htaccess already has the below rules to handle file extensions and caching.

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]


RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>

Any advice would be appreciated.

Update: File Structure

enter image description here

1 Answer 1

1

If you want a specific url to load a specific file:

RewriteRule ^about-us(|/)$ views/about-us.php [L]
Sign up to request clarification or add additional context in comments.

12 Comments

apologies, didn't work and I can't figure out why. theoretically it should
Where is your htaccess located?
it's in the root of the project, I'm thinking maybe the rewrite rules in my htacess are stopping the above solution form working?
In the project folder?
yeah the root, the folder where ALL my project files are, and it is working because pages load fine without file extensions
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.