URL-Rewriting help
I am new to URL rewriting and saw in many sites the effect of URL Rewriting. I am completely new to this area. Even, i am finding hard to learn this.
The help is, I want to rewrite http://www.example.com/resources/pages/demos/any-page.html
to
http://www.example.com/demos/any-page.html
omitting the resources/pages/
directory.
I hope this rewriting is possible and i开发者_如何学Gof please help me in providing the .htaccess code for this rewrite. I am using a linux server.
mod_rewrite isn't the easiest thing to grasp at first. I think you'll find the following code sufficient:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^demos/(.*)\.(htm|html)$ resources/pages/$1.$2 [L]
This needs to be placed in the document root of your site. It will handle both .html and .htm pages and match only those pages. To match any page after the demos/ url (With any extension) use the following:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^demos/(.*)$ resources/pages/$1 [L]
put .htaccess
at /
, and in that file:
RewriteEngine On
RewriteRule ^demos/(.*)\.html resources/pages/demos/$1.html
精彩评论