I am trying to remove part of a dynamic URI from Apache. I tried different rewrite rules but I'm not getting anywhere. I was able to clean the URL using query string but that
deletes anything after accessdenied
but we need group part for application to work.
The URI ends with:
accessdenied?group=test&oam_res=...
Whatever comes after &oam_res
should be removed.
The question is a bit vague, but I guess this is going to point you into the right direction:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^([^&]*&)*oam_res=
RewriteRule ^/?accessdenied$ /accessdenied?%1 [R=301]
Note that this implements an external redirection, so it changes the URL visible in the client (browser). If you only want to do an internal rewrite then you need to replace the [R=301]
flag with the [L]
flag.
For this to work you obviously need to have the rewriting module installed, loaded and enabled in your http server. In case you want to use a dynamic configuration file (.htaccess
) you need to enable its interpretation too using the AllowOverride
directive. But you should always prefer to place such rules inside the http servers (virtual) host configuration instead of using dynamic configuration files (.htaccess
style files). Those files are notoriously error prone, hard to debug and they really slow down the server. They are only supported as a last option for situations where you do not have control over the host configuration (read: really cheap hosting service providers) or if you have an application that relies on writing its own rewrite rules (which is an obvious security nightmare).