Forum Moderators: phranque

Message Too Old, No Replies

invisible redirecting using mod_rewrite with exceptions

redirect pages unless the contan .?&=

         

jelleast

8:50 pm on Jan 10, 2006 (gmt 0)

10+ Year Member



i want to translate this little piece of code in apache style so i can use it in a .htaccess file,

but i have realy no idea how to do it...

If(no ‘.’ or ‘?’ or ‘&’ or ‘=’ in url after last ‘/’){
[127.0.0.1...] →
[127.0.0.1...]
}

in this script "moeder" could be changed in anything else, and will be rewritten after "?page=display&book=", unless it contains a ‘.’ or ‘?’ etc.

so if i use:
[127.0.0.1...]
the script will not try to redirect that to
[127.0.0.1...]

i hope someone can help me out
most sincerly

jelle van oosten

jdMorgan

3:39 pm on Jan 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Jelle,

Welcome to WebmasterWorld!

You could try something like this:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{REQUEST_URI} !\.[^/]*$
RewriteRule ^tryout/(.+) /tryout?page=display&book=$1

What you need to know:

In Apache, query strings are handled separately from URLs. That is, anything after a "?" is stored and handled in the server variable %{QUERY_STRING) and will not be visible to RewriteRule.

For this reason, it is only necessary to check for "." followed by anything but "/" in the URL itself -- the "=" and "&" characters will all be placed in the %{QUERY_STRING) variable, and the "?" is removed; It appears in neither the local URL-path nor the %{QUERY_STRING)

I hope I understood your question. If so, then that above code wshould work with a few minor tweaks.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim