Re: RewriteMap and patterns

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

What I would do is RewriteRule with just [L] tag for internal redirection or [R,L] if you don't mind the redirection to be external.

Since I haven't seen the whole configuration my guess is you don't have the proper handler defined for the resulting url and that's why you get a 404, and in those cases a is when fallbackresource is ideal, to hand those requests to where they must end.

Generally when I use passthrough [PT] is because the end url will be dealt with the appropiate handler, but you don't seem to have a rule for the destination to be handled in php, so how come you expect anything else other than a 404?

That is briefly what I would do:

First make the proper redirections:

  RewriteEngine on
  RewriteMap lsv2ids "txt:/etc/httpd/conf.d/linuxsecurity-lsv2ids.map"
  RewriteRule "/content/view/(.*)" "${lsv2ids:$1}" [R,L]

Define the fallback for requests not ending in PHP but for which I hand the php handler to deal them.
  FallbackResource /index.php

Define the handler for php file requests
<FilesMatch \.php>
  SetHandler "proxy:unix:/run/php-fpm/linuxsecurity.sock|fcgi://localhost"
</Filesmatch>

I've got all this working. However, we currently have a PHP script that's used to catch requests that are not in our static map. It is spawned from Joomla. Normally, when a URL like the following is requested and no match is found in our static map:

https://linuxsecurity.com/content/view/127853

it is then passed onto the PHP script from within Joomla that sets the Location to something like:

https://linuxsecurity.com/redirection/index.php?type=view&ids=127853&uri=/content/view/127853/

The redirection.php script's function is to perform an SQL query that tries to identify the current name from that article ID and redirects the user to something like the following:

https://linuxsecurity.com/news/network-security/the-changing-security-threat-of-email-attacks

I'd like to be able to use the static map for the IDs I do know, and send any others to the redirect script directly from within my apache config directly. Is this possible?

Something like this:

  RewriteEngine on
  RewriteMap lsv2ids "txt:/etc/httpd/conf.d/linuxsecurity-lsv2ids.map"
  RewriteRule "/content/view/([0-9]{6})/?" "${lsv2ids:$1}" [L]

  RewriteRule "/content/view/([0-9]{6})/?" "https://linuxsecurity.com/redirection/index.php?type=view&ids=$1&uri=$1"

I don't see how this would work, since both rules contain the same pattern. Ideas on how to go about this would be appreciated. Perhaps a RewriteMap prg rule?

  RewriteMap mapper "prg:/etc/httpd/conf.d/mapper.php"
  RewriteRule "/content/view/([0-9]{6})/?" "${mapper:$1}"

Thanks,
Dave





[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux