Forum Moderators: phranque

Message Too Old, No Replies

Rewrite for ask point in url and exception for subdirectories .

Rewrite for ask point in url and exception for subdirectories ...

         

leandre

8:05 pm on Jan 2, 2009 (gmt 0)

10+ Year Member



Hello and happy new years :)

I have little problem :

http://www.example.com/?
http://www.example.com/toto/?
http://www.example.com/toto/abc/?
http://www.example.com/toto/abc/ect/?

Im search solution for remove ? in my url but i have one exception and is for one subdomains

http://www.example.com/forums/index.php?t=msg&goto=12368&#msg_12368

Under /forums/ ? is allow

I try many test, but nothing work. Do you have any idea ?

Bye

jdMorgan

9:31 pm on Jan 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please post your best-effort code as a basis for discussion.

Thanks,
Jim

leandre

9:38 pm on Jan 2, 2009 (gmt 0)

10+ Year Member



Sorry,

I try this :

RewriteRule ^(([^/]+/)*[^.]*)\?$ http://www.example.com.com/$1 [R=301,L]

RewriteCond %{DOCUMENT_ROOT}/$1 -f
RewriteRule ^(([^/]+/)*[^.]*)\?$ http://www.example.com.com/$1 [R=301,L]
#
RewriteCond %{DOCUMENT_ROOT}/$1/ -d
RewriteRule ^(([^/]+/)*[^.]*)\?/?$ http://www.example.com.com/$1/ [R=301,L]

If im replace ? by - the code is work :(

jdMorgan

11:05 pm on Jan 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RewriteRule cannot "see" query strings attached to a URL, and even RewriteCond looking at %{QUERY_STRING} cannot see the "?" itself.

So, in order to detect a question mark with either a blank or a non-blank query string, you have to examine %{THE_REQUEST}:


# Remove trailing query strings from all URL-paths ending in "/"
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^?]*\?
RewriteRule ^(([^/]+/)*)$ http://www.example.com/$1? [R=301,L]

Note that the "?" at the end of the RewriteRule substitution URL is a mod_rewrite operator which clears the query string. This "?" *will not* appear in the redirected URL.

Jim

[edited by: jdMorgan at 2:33 am (utc) on Jan. 3, 2009]

leandre

11:12 pm on Jan 2, 2009 (gmt 0)

10+ Year Member



Ok thank you for information for QUERY_STRING.

But you rule is doesnt work :(

jdMorgan

11:40 pm on Jan 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Actually, it does work -- on many servers.

Did you flush your browser cache before testing?

Did you read the comments, and test with a URL ending in a slash, as described previously?

If you want further help, then please tell us how you tested, tell us what you expected, and tell us what actually happened.

Jim

g1smd

11:40 pm on Jan 2, 2009 (gmt 0)

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



In what way does it "not work"?

"Not work" is far too vague as a description of what happens.

leandre

11:59 pm on Jan 2, 2009 (gmt 0)

10+ Year Member



Sorry,

I flush my cache of my browser allways time before test.

This is my .htaccess

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^?]*\?
RewriteRule ^(([^/]+/)*)$ http://www.example.com/$1? [R=301,L]

When i try :

http://www.example.com/?
http://www.example.com/toto/?
http://www.example.com/toto/abc/?
http://www.example.com/toto/abc/ect/?

The code of return is 200, not 301.
Im search when i have this url :
http://www.example.com/?
is return 301 to
http://www.example.com/

Thanks,

leandre

12:59 am on Jan 3, 2009 (gmt 0)

10+ Year Member



Thank you for your help and you have write. QUERY_STRING is bad direction.

This is a solution :

RewriteCond %{THE_REQUEST} \?\ HTTP [NC]
RewriteRule .? http://www.example.com%{REQUEST_URI}? [R=301,L]

And happy new year