2

Does anyone know how to change the URL for all php files inside a subfolder of the root directory and also remove .php?

http://localhost/pages/x.php to http://localhost/x

Example: http://localhost/pages/example.php to http://localhost/example

2 Answers 2

1

You can do it like this, which only executes if the request exists in pages and doesn't exist in root. So existing items in root don't get rewritten.

RewriteEngine on
RewriteCond %{CONTEXT_DOCUMENT_ROOT}/$1 !-f
RewriteCond %{CONTEXT_DOCUMENT_ROOT}/pages/$1.php -f
RewriteRule ^([^/]+)$ pages/$1.php
Sign up to request clarification or add additional context in comments.

Comments

1
RewriteEngine On

RewriteRule ^x$ page/x.php [L]
RewriteRule ^example$ pages/example.php [L]

Comments

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.