Short link hide subfolders

New to mod_rewrite? This is a good place to start.

Short link hide subfolders

Postby sqr » Thu May 21, 2009 2:41 am

Hi

I have this link

www.mydomain.com/pages/main/page.html

and how to write rule for mode rewrite for link like this:

www.mydomain.com/page.html

Pages are genereted from CMS and have always /pages/main/. I want to write rule working for all pages.
sqr
 
Posts: 4
Joined: Thu May 21, 2009 2:31 am

Postby richardk » Thu May 21, 2009 6:59 am

Is /pages/main/page.html an existing file?
Do you have any mod_rewrite at the moment?

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule %{DOCUMENT_ROOT}/pages/main%{REQUEST_URI} -f
RewriteRule ^[^/]+\.html$ /pages/main/$0 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Thanks richardk

Postby sqr » Thu May 21, 2009 12:19 pm

This rule works :)

I have above only one rule

AddType application/x-httpd-php .html

and /pages/main/page.php realy exist.

But I have one more question. In this CMS folder /pages/main/ is only for first menu level. When user create somthing like this:

main
-Offer folder
-----First page.html
-----Second page.html
- Contact folder
- About Us folder
- Offer page.html
- Contact page.html
- About Us.html


This rule dosen't work for First page.html. Patch to this page is :

www.mydomain.com/pages/main/offer/firstpage.html

How to write rule for firstpage.html?
sqr
 
Posts: 4
Joined: Thu May 21, 2009 2:31 am

Postby richardk » Thu May 21, 2009 4:10 pm

Replace
Code: Select all
[^/]

which doesn't match slashes with
Code: Select all
.

which does.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby sqr » Thu May 21, 2009 10:51 pm

Hi

This rule must be modified that?

Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule %{DOCUMENT_ROOT}/pages/main%{REQUEST_URI} -f
RewriteRule ^.+\.html$ /pages/main/$0 [QSA,L]


Because this rule dosen't work :(
sqr
 
Posts: 4
Joined: Thu May 21, 2009 2:31 am

Postby richardk » Fri May 22, 2009 8:14 am

Is it giving you a 404 error?

You are visiting /offer/firstpage.html, it should go to /pages/main/offer/firstpage.html and /pages/main/offer/firstpage.html is an existing file?

Where is the mod_rewrite?

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule %{DOCUMENT_ROOT}/pages/main/$0 -f
RewriteRule ^.+\.html$ /pages/main/$0 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 110 guests

cron