htaccess rewrite remove parent directory and php extension
I 开发者_Go百科need a hand rewriting some urls. What i need is to remove the folder name from the url and also remove the php file extension. Example:
I need mysite.com/foldername/about.php
to become
mysite.com/about/
I must say that i have several php static files that need to be access from
mysite.com/filename/
instead of
mysite.com/foldername/filename.php
Thank you in advance for your time.
Kind regards.
RewriteEngine On
RewriteRule ^/[.*]/?$ foldername/$1.php#{QUERY_STRING} [NC,L]
If you are not using the QUERY_STRING (i.e. you have no $_GET parameters) then you can remove the #{QUERY_STRING}
Note, this will rewrite everything in your root to foldername/NAME.php
If you wish to exclude certain paths (such as css, js files and others), I recommend you do:
RewriteCond RewriteCond %{REQUEST_URI} !^*.css$
RewriteCond RewriteCond %{REQUEST_URI} !^*.js$
RewriteCond RewriteCond %{REQUEST_URI} !^*.php$
RewriteCond RewriteCond %{REQUEST_URI} !^*DONTREDIRECT*$
RewriteRule ^/[.*]/?$ foldername/$1.php#{QUERY_STRING} [NC,L]
精彩评论