Hey friends, this one is the last blog on Advanced Mod_Rewrites Example From Wordpress. hope the previous both blogs are helpful to you.  So let us start...

 

#21 - Map any request to a handler

In the case where all URIs should be sent to the same place (including potentially requests for static content) the method to use depends on the type of the handler. For php scripts, use: For other handlers such as PHP scripts, use:

RewriteCond %{REQUEST_URI} !=/script.php
RewriteRule .* /script.php

 

 

#22 - And for CGI scripts:

ScriptAliasMatch .* /var/www/script.cgi

 

 

#23 - Map URIs corresponding to existing files to a handler instead

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f
RewriteCond %{REQUEST_URI} !=/script.php
RewriteRule .* /script.php

If the existing files you wish to have handled by your script have a common set of file extensions distinct from that of the hander, you can bypass mod_rewrite and use instead mod_actions. Let's say you want all .html and .tpl files to be dealt with by your script:

Action foo-action /script.php
AddHandler foo-action html tpl

 

 

#24 - Deny access if var=val contains the string foo.

RewriteCond %{QUERY_STRING} foo
RewriteRule ^/url - [F]

 

 

#25 - Removing the Query String

RewriteRule ^/url /url?

 

 

#26 - Adding to the Query String

Keep the existing query string using the Query String Append flag, but add var=val to the end.

RewriteRule ^/url /url?var=val [QSA]

 

 

#27 - Rewriting For Certain Query Strings

Rewrite URLs like http://askapache.com/url1?var=val to http://askapache.com/url2?var=val but don't rewrite if val isn't present.

RewriteCond %{QUERY_STRING} val
RewriteRule ^/url1 /url2

 

 

#28 - Modifying the Query String

Change any single instance of val in the query string to other_val when accessing /path. Note that %1 and %2 are back-references to the matched part of the regular expression in the previous RewriteCond.

RewriteCond %{QUERY_STRING} ^(.*)val(.*)$
RewriteRule /path /path?%1other_val%2

 

 

With this, we are ending this series of Advance .htaccess mod_rewrite. hope this is helpful for you. Kindly share your valuable feedback and comments below. Stay tuned for further blogs.