views:

39

answers:

2

Hello,

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 if please help me in providing the .htaccess code for this rewrite. I am using a linux server.

A: 

put .htaccess at /, and in that file:

RewriteEngine On
RewriteRule ^demos/(.*)\.html resources/pages/demos/$1.html
Mewp
A: 

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]
Marco Ceppi
Marco, i tried your method, but its not working. I went to `http://www.example.com/demos/index.html` but i get a 404 error page. I added the .htaccess file to `example.com/.htaccess`. Any suggestions ?
Aakash Chakravarthy
Does the demos folder actually exist?
Marco Ceppi
Also that code worked for me - however you will need to ensure two things:mod_rewrite is enabled and that `AllowOverride` is set to All in httpd.conf (Or in the "Sites-enabled" section on Ubuntu
Marco Ceppi
@Marco, mod_rewrite is enabled and AllowOverride is set to all. when i tried, `http://www.example.com/demos/demos/index.html` it worked. A extra `demos` folder is the mistake.
Aakash Chakravarthy
That doesn't make any sense. Does the demos folder (the first one) exist?
Marco Ceppi