Forum Moderators: phranque

Message Too Old, No Replies

rewrite only if no post variable

         

agriz

9:46 am on Jul 3, 2010 (gmt 0)

10+ Year Member



Hi,

I am having little problem. I am here for your help again.

I want index.php to redirected domain name. and i did this with the following code.


RewriteEngine on
Options +FollowSymLinks
RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^(.*)index.php$ sitename [R=301,L]


But my site is calling all the subpages like this.
index.php?dll=login, index.php?dll=register

To preserve this i did like this.


RewriteEngine on
Options +FollowSymLinks
RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^(.*)index.php(.*)$ domain.com/$2 [R=301,L]


but it is post any form variable

So, is there a way to redirect only if there is no query string in index.php and if there is no form post variable?

awaiting for your reply

Regards
Mahesh

agriz

9:49 am on Jul 3, 2010 (gmt 0)

10+ Year Member



* but it is post any form variable (I typed wrongly)

That method is not posting any form variable.

agriz

3:31 pm on Jul 4, 2010 (gmt 0)

10+ Year Member



Hi,

Please help me on this

Regards
Mahesh

g1smd

6:31 pm on Jul 4, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You can test to make sure that QUERY_STRING is non-blank in another RewriteCond.

agriz

11:03 pm on Jul 4, 2010 (gmt 0)

10+ Year Member



Hi,

Sometimes, the query string will be empty but there will be some form post variable.

I did something in php.

if($url == site/index.php && count(get) == 0 && count(post) == 0)
{
301 redirection
redirect to site.com
}

It is working as i expected.
is that good?

I am not good in apache

jdMorgan

4:46 am on Jul 6, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



POST data is not visible at the server config level, as it is not part of the HTTP headers sent by the client that can be examined by the server.

So yes, you will have to do POST-based redirects within the script itself, after reading-in and checking the content-body.

Also, be aware that for security reasons, user-agents (browsers) are supposed to NOT accept redirection of previously-submitted POST requests without user confirmation. See the HTTP/1.1 protocol specification.

It may be that you are looking for a round-about way to determine GETs from POSTs. If so, be aware that the RewriteCond directive in mod_rewrite can test the server variable %{REQUEST_METHOD} for "GET" or "POST" methods directly, or it can extract the HTTP method from the beginning of the mod_rewrite variable %{THE_REQUEST}. THE_REQUEST is the HTTP request line sent by the client, exactly as it appears in your raw server logs. Note however that THE_REQUEST is a variable which is available only within mod_rewrite.

Jim