开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜