开发者

URL-Rewriting help

开发者 https://www.devze.com 2023-01-08 19:30 出处:网络
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.

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

精彩评论

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