Forum Moderators: coopster

Message Too Old, No Replies

.htaccess ruined on form process

DreamWeaver's $editFormAction = $_SERVER['PHP_SELF'];

         

fwordboy

3:05 pm on Jan 25, 2005 (gmt 0)

10+ Year Member



using DreamWeaver MX 2004's PHP code

<form action="<?php echo $editFormAction;?>" method="POST" etc

couple with this code in the head (also courtesy of DWMX 2004:

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

completely ruins my people/search-engine friendly URLs (created with mod_rewrite thru .htaccess) and turns my URLs back into query strings? how do I avoid this?

Birdman

9:59 pm on Jan 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, there is no need to worry about a query string on the resulting page of a form submittal. search engines won't ever see it.

However, to remove it I would simply remove the if(){} section and leave it at:

$editFormAction = $_SERVER['PHP_SELF'];

fwordboy

2:59 pm on Jan 27, 2005 (gmt 0)

10+ Year Member



I'm pretty sure, by removing the if statememnt makes the page refresh to just index.php without any rewritten query strings, so on form submittal the user would get sent back to a the page two levels up in the site hierachy. e.g. from
site.com/level1/level2/page-with-form/

to
site.com/level1/index.php

p.s. although search engines are a worry, i think it is more important not to bombard visitors to my site with horribly ugly urls that could confuse them.

Birdman

4:16 pm on Jan 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok, I think I understand better now. You want the form to submit to itself, but PHP_SELF is giving you the unfriendly URL.

The solution would be to rebuild the "friendly" URL using the query string variables. Using your example:

suppose...

site.com/level1/level2/page-with-form/

...gets rewritten to...

/index.php?lev_1=level1&lev_2=level2&lev_3=page-with-form

In the script, the form action would be...

$editFormAction = '/' . $_GET['lev_1'] . '/' . $_GET['lev_2'] . '/' . $_GET['lev_3'] . '/';

Which would give you the original URL...

/level1/level2/page-with-form/

I hope that helps a bit.

fwordboy

4:52 pm on Jan 27, 2005 (gmt 0)

10+ Year Member



perfect. thanks