Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

306
Views
¿Por qué '/' es el primer uri evaluado por Apache Rewrite?

Actualmente estoy trabajando en un servidor de desarrollo de Windows 10/Apache2.4/PHP 7.3 y accediendo a esta URL (es decir, donde el servidor raíz es localhost y el 'nombre de host' se asigna a través del archivo 'hosts'): hostname/page.php?m=150

Quiero usar los comandos de reescritura de Apache para redirigir cualquier URL con este patrón a hostname/homepage.php pero el archivo de registro me muestra que mis comandos no se están evaluando de la forma en que esperaría que se evaluaran.

FYI, el sitio está configurado por un bloque <VirtualHost> en httpd-vhosts.conf, por lo que es donde se alojan mis comandos de reescritura.

He reducido el bloque de host virtual a solo esto:

 <VirtualHost *:80> DocumentRoot "C:/Apache24/htdocs/{sitename}" ServerName {sitename} ServerAlias {sitename} Options -FollowSymLinks -Indexes -MultiViews RewriteEngine On LogLevel alert rewrite:trace6 #Just testing to see if the command block is found #Note: The log file reports this as a match. RewriteCond %{HTTP_HOST} sitename #part 1: IF the URI starts with /page.php... #the show stops here...Apache finds no match, with or without the '/'. #even though page.php is entered into the browser, it is never evaluated RewriteCond %{REQUEST_URI} ^/page.php #Part 2: AND there's a query string that matches this pattern #this condition is never reached since Part 1 fails RewriteCond %{QUERY_STRING} ^m=[0-9]{1,3}$ #THEN: rewrite the url and go to /homepage.php (forgetting the query) RewriteRule (^.$) /homepage.php [R=301,QSD,END] ErrorLog "logs/sitename_error.log" </VirtualHost>

Cuando coloco hostname/page.php?m=150 en el navegador, la línea {REQUEST_URI} no coincide. Cuando miro siteroot_error.log, las primeras 3 entradas en el registro se ven así (se eliminaron los datos ilegibles):

 .... init rewrite engine with requested uri / #WHY / and not /page.php???? .... applying pattern '(^.$)' to uri '/' .... RewriteCond: input='hostname' pattern='hostname' => matched #Duh! .... RewriteCond: input='/' pattern='/page.php' => not-matched .... pass through / .... init rewrite engine with requested uri /index.php .... RewriteCond: input='' pattern='^m=[0-9]{1,3}$' => not-matched

entrada en el registro está evaluando la solicitud '/'. ¿No debería estar evaluando '/page.php'? En cualquier caso, no encuentra ninguna coincidencia, por lo que pasa '/'. Como resultado, apache luego agrega 'index.php' ya que es el primer archivo establecido en el parámetro DirectoryIndex en el archivo de configuración del servidor apache. Y, en este caso, no hay ningún archivo index.php o index.html en el directorio '/', por lo que la solicitud falla.

En mi opinión, la primera evaluación que debería aparecer en el archivo de registro es la evaluación de '/page.php' y apache debería intentar hacerla coincidir con el patrón ('/page.php'). ¿Qué me estoy perdiendo? ¿Por qué la reescritura está tratando de hacer coincidir '/'?

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!