Redirection of cgi-bin in .htaccess

0

In my project I have some urls with the following format

xxx/cgi-bin/index.pl/c/10/yyy/

where, xxx is the web address.

I would like the cgi-bin/index.pl route to appear in these urls.

I have been testing different configurations of the .htaccess, but I have not managed to eliminate that part, leaving xxx/c/10 .

Edit:

At Mariano's request, I comment that both the css, js files, images ... I have them out of the path of / cgi-bin, in another folder / html.

I have no idea how to indicate that this hangs from another directory and that the url redirects me the part of perl scripts to the route without /cgi-bin/index.pl ...

    
asked by yhazius 29.11.2017 в 15:03
source

1 answer

0
  

I have no idea how to indicate that this hangs from another directory and that the url redirects me the part of perl scripts to the route without /cgi-bin/index.pl

If you have no idea, less who wants to answer you. You have to define something so that Apache can define where to rewrite.


I can think of 2 ways:

1. Rewrite if you do not have an extension of css / html / js / etc

An option, I do not know if it's useful, but I suppose it's the most viable in this case, it's rewriting depending on the extension of the file. In this way, we generate exceptions for each extension that you want to search outside of /cgi-bin/index.pl .

RewriteEngine On
RewriteBase /

#Si no termina con estas extensiones
RewriteCond %{REQUEST_URI} !\.(?:html?|css|png|jpe?g|gif)$ [NC]
#Reescribir
RewriteRule (.+) cgi-bin/index.pl/$1 [L]

To which you should complete the list of file extensions that you do not have to rewrite.


2. Put exceptions to specific folders

Or we can rewrite, as long as you do not try to access any of the folders that you want to use as an exception.

RewriteEngine On
RewriteBase /

#Si no empieza con alguna de estas carpetas:
RewriteCond %{REQUEST_URI} !^(?:img|images|scripts|proyecto|bla|etc)(?:/|$) [NC]
#Reescribir
RewriteRule (.*) cgi-bin/index.pl/$1 [L]


Other options could be:

  • Rewrite cgi-bin/index.pl/ if the URL that is accessed does not exist.
  • The 2 option but vice versa, rewrite only if it is a list of folders within cgi-bin/index.pl/ predefined.
  • Rewrite only if the file exists in cgi-bin/index.pl/ .
  • Rewrite only if you try to access a resource that is terminated in .pl .
  • Open another port other than 80, and not rewrite in that port, then you would access your images as http://tusitio.ext:1234/tu-script.js (with the problem that another domain considers it).

... in short, some rule has to be fulfilled to differentiate it, but you are the programmer, and defining that is your task.

    
answered by 01.12.2017 в 12:57