Use child pages to validate parent pages

Discuss practical ways rearrange URLs using mod_rewrite.

Use child pages to validate parent pages

Postby Ulysses » Wed Apr 14, 2010 2:52 pm

Hi there,

I have a script that uses the RewriteRule for tidy URLs. So for example, to get content using about.html or about/company.html I am using:

Code: Select all
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?PAGE=$1 [L,QSA]


This is working fine. However, for forms such as contact.html I want to be able to dynamically return success and error child pages (I am presently returning the same form, which doesn't help analytics).
For example, from contact.html I want to call either contact/success.html or contact/error.html but not sure where to go from here:

Code: Select all
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)/success.html$ contact.html&return=success [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)/error.html$ contact.html&return=error [L,QSA]


The above works if I hardcode contact.html (the parent of the success and error pages) but I'd ideally like the htaccess file to be flexible so as to automatically use the parent page such as contact.html so as to work for all forms anywhere within the website.

I was thinking something like:

Code: Select all
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)/error.html$ ^(.*)&return=error [L,QSA]
[/code]

Any ideas?
Ulysses
 
Posts: 10
Joined: Thu Sep 18, 2008 7:58 am

Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron