Forum Moderators: phranque

Message Too Old, No Replies

URL Rewriting for Folders

         

norbiu

4:27 pm on Jun 26, 2012 (gmt 0)

10+ Year Member



I have an app located at example.com/app with signin.php, signup.php, index.php, etc inside the folder.

Now the client wants to have the app accessible at example.com/signin.php and so on, but I want to keep the app files inside the app folder for better management.

I tried using this, and it works, but then I can't access the files that I already had in the root directory:

RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteCond %{REQUEST_URI} !^/app/
RewriteRule (.*) /app/$1

Is there a way to exclude pages in the root directory from being affected? Or is there a better way to do this?

g1smd

5:22 pm on Jun 26, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



(.*) matches all URL requests - that's all URL requests in the root or in any folder.

You are therefore rewriting "all" requests to the /app/ folder.

You need to swap the (.*) for a more specific pattern - one that matches only the URL requests that need to be rewritten.

Additionally, your first two RewriteConditions are completely redundant and can be removed.

lucy24

12:17 am on Jun 27, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



your first two RewriteConditions are completely redundant and can be removed

Or, better yet, they can be replaced with a universal domain-name redirect positioned before all the Rewrites ;)

signin.php, signup.php, index.php

Does the "etc." represent a vast number of files, with no unifying feature in the names? Or is there a finite number of files to rewrite?

Please say you-- or the client-- don't want to rewrite /app/index.php, or there will be a big mess. I assume there's already a root-level index.php.