0

I have a site with files contained in a /pages/ dir. I'm trying to hide the /pages/ directory from URLs but still have them in the directory, so basically I am trying to achieve this:

www.example.com/sub/

should load:

www.example.com/pages/sub/

or

www.example.com/sub/file.php

should load:

www.example.com/pages/sub/file.php

-- the aim here is to remove /pages/ from all urls

thanks in advance

2 Answers 2

3
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ pages/$1 [QSA,L]

If file or directory doesn't exist, then try in pages folder.

QSA adds url parameters if any (like ?param1=val1&param2=val2)

Sign up to request clarification or add additional context in comments.

Comments

1

Apache Re-write: http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

Learn it.

Live it.

Hate it?

edit: its a first in first evaluated, last in last evaluated process, so be considerate when specifying rules, as even if one is established correctly, a broader, more general one which also meets the same pattern (depending on wildcards) has the chance to usurp the prior ( think CSS declaration squashing, if you're familiar with that )

4 Comments

thanks for the url, would look through it and keep trying.
the simple answer is RewriteEngine on NEWLINE-> RewriteRule "^/pages/$" "/" but Rewrite is deceptively "easy" and can cause serious headaches if not fully understood
@BrandtSolovij that should be in your actual answer, as it is it's basically a "rtfm"-comment at best.
@ccKep apache rewrites are arguably the gateway drug to full on grok. If the asker made an attempt and posted what they tried - id have capitulated the way you suggest i shoukd have. They didnt so i didnt. Its a valuable question so i didnt flag for repition

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.