Estoy tratando de redirigir mi url:
www.site.com/dashboard/invest-package.php?packageID=1
a
www.site.com/dashboard/invest-package/1
En realidad, resolví este problema con -
<a href="invest-package-'.$row['packageID'].'">Invest</a>
RewriteRule ^invest-package-(.*)$ invest-package.php?packageID=$1 [QSA,L]
Pero quería hacer con "/" no me gusta usar "-". Las soluciones que encontré en Internet no funcionaron. Sigo recibiendo el error 404 no encontrado.
Aquí está mi enlace a invest-package.php
<a href="invest-package/'.$row['packageID'].'">Invest</a>
y archivo .htaccess:
Options -Indexes RewriteEngine On RewriteBase /dashboard/ RewriteCond %{REQUEST_FILENAME} !-d [NC] RewriteCond %{REQUEST_FILENAME} !-f [NC] RewriteRule ^invest-package/(.*)$ invest-package.php?packageID=$1 [QSA,L]
Puedes probar este código:
Options -Indexes -MultiViews RewriteEngine On RewriteBase /dashboard/ RewriteCond %{REQUEST_FILENAME} !-d [NC] RewriteCond %{REQUEST_FILENAME} !-f [NC] RewriteRule ^invest-package/([\w-]+)/?$ invest-package.php?packageID=$1 [QSA,L,NC]
Es importante desactivar MultiViews
, es decir, el servicio de negociación de contenido de Apache.
La opción MultiViews
(ver http://httpd.apache.org/docs/2.4/content-negotiation.html ) es utilizada por Apache's content negotiation module
que se ejecuta antes de mod_rewrite
y hace que el servidor Apache coincida con las extensiones de los archivos. Entonces, si /file
es la URL, Apache servirá /file.php
sin ningún parámetro GET
.