Mod_rewrite failing to silently redirect

2 days of struggling and about a pound less of hair, I figure it's about time I ask for some help. I've recently migrated my project to a main sub-directory so that the structure is as follows:

-application/
   -index.php
   -signup/
      -index.php
      -signup_set.php
-css/
-js/

I've been trying to get mod_rewrite to do my work for me to exclude "application/" from all the urls. Here is where I got in my root .htaccess:

RewriteEngine On 

#first round through, prepend 'application/' to request
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !^application

RewriteRule ^(.*)$ application/$1 [L]

#second round through, if the new url is not directory or file, append .php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*)$ $1.php [L] 

I may have a terrible understanding of regex/mod_rewrite, but this actually seems to partly work. Partly. The weird part about this is that when I route to a "pretty url" (e.g. www/signup) the url in the top bar is physically rewritten to include the "application/" (e.g. www/application/signup). So somehow this "silent" rewriting process is getting pretty loud...Any suggestions? I realize I could change my root directory but that would require rewriting of code referencing css/js files. I'm more curious than anything, just trying my hand at some htaccess. Any help would be appreciated! Thanks StackOverflow, you rock.

P.S. I'm running Apache on Windows 7 and using a virtual host (in case any of that is relevant)

Answers


The rules below work for me running Apache on Windows 7 using a virtual host. All I changed was the second RewriteCond.

RewriteEngine On

# Append trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(?:\.\w+|/)$
RewriteRule ^(.*)$ /$1/ [L]

# First round through, prepend 'application/' to request
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/application
RewriteRule ^(.*)$ application/$1 [L]

# Second round through, if the new url is not directory or file, append .php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.\w+$
RewriteRule ^(.*)/$ $1.php [L]

Need Your Help

Methods which are better or alternative to Self Organized Maps to get basic understanding/relationship of the data

machine-learning data-visualization k-means som self-organizing-maps

I have been working on the concept of Self Organized Maps to get an understanding/ relationship of variables in any type of dataset and produce some heatmaps. Is there any other machine learning co...

dojo/subscribe does not work if the document is not ready

javascript dojo

I have a small requirement. We have a application controller and a custom dijit which work together with each other.