htaccess no funciona como se requiere
Frecuentes
Visto 43 veces
0
I cannot get my .htaccess file working properly. Please can someone help me correct it.
solía http://htaccess.madewithlove.be/ to try and get it correct, but with no success.
http://www.mydomain.co.uk/bootstrap/rolex-watch.php should show in the address bar as http://www.mydomain.co.uk/bootstrap/rolex-watch and show the rolex-watch.php page
http://www.mydomain.co.uk/bootstrap/products.php?f=Watch&b=Tissot&t=T-Touch should show in the address bar as http://www.mydomain.co.uk/bootstrap/products/Watch/Tissot/T-Touch and show the products page with f and optional parameters b and t parameters set.
.htaccess File contents
ErrorDocument 404 /bootstrap/404.php
ErrorDocument 403 /bootstrap/403.php
Options +FollowSymLinks
Options +Indexes
RewriteOptions inherit
RewriteEngine on
RewriteRule ^bootstrap/products/(.*)/(.*)/(.*)$ bootstrap/products.php?f=$4&b=$5&t=$6
RewriteRule ^bootstrap/products/(.*)/(.*)$ bootstrap/products.php?f=$4&b=$5
RewriteRule ^bootstrap/products/(.*)$ bootstrap/products.php?f=$4
RewriteRule ^bootstrap/products/search/(.*)$ bootstrap/products.php?s=$1
Redirect bootstrap/rolex-watch.php http://www.mydomain.co.uk/bootstrap/rolex-watch
Redirect bootstrap/scrap-gold.php http://www.mydomain.co.uk/bootstrap/scrap-gold
Redirect bootstrap/eternity-ring.php http://www.mydomain.co.uk/bootstrap/eternity-ring
Redirect bootstrap/engagement-ring.php http://www.mydomain.co.uk/bootstrap/engagement- ring
Redirect bootstrap/wedding-ring.php http://www.mydomain.co.uk/bootstrap/wedding-ring
Redirect bootstrap/diamond-ring.php http://www.mydomain.co.uk/bootstrap/diamond-ring
Redirect bootstrap/inferno-diamonds.php http://www.mydomain.co.uk/bootstrap/inferno- diamonds
Redirect bootstrap/radley-products.php http://www.mydomain.co.uk/bootstrap/radley-products
RewriteRule ^([^\.]+)$ $1.php [NC,L]
2 Respuestas
0
Firstly, you have some stray spaces in your mod_alias Redirect
directivas:
Redirect bootstrap/engagement-ring.php http://www.mydomain.co.uk/bootstrap/engagement- ring
Redirect bootstrap/inferno-diamonds.php http://www.mydomain.co.uk/bootstrap/inferno- diamonds
These will cause a 500 server error, because it has the incorrect 3 parameters.
En segundo lugar, tu Redirect
directives need to match against a leading /
, so they all need to look like:
Redirect /bootstrap/rolex-watch.php http://www.mydomain.co.uk/bootstrap/rolex-watch
But those 2 issues are really just moot because you've created a redirect loop by rewriting the URI with your last rule, and redirecting de nuevo mediante el Redirect
statements. The two different modules that you are using, mod_alias (Redirect
) and mod_rewrite (Rewrite*
) both get applied to the same URI at different point in the URI processing pipeline, and thus they both mangle the same URI. You need to stick with just mod_rewrite and add a check at the very beginning to prevent looping altogether:
# This prevents the rules from looping
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
RewriteRule ^bootstrap/products/(.*)/(.*)/(.*)$ bootstrap/products.php?f=$4&b=$5&t=$6
RewriteRule ^bootstrap/products/(.*)/(.*)$ bootstrap/products.php?f=$4&b=$5
RewriteRule ^bootstrap/products/(.*)$ bootstrap/products.php?f=$4
RewriteRule ^bootstrap/products/search/(.*)$ bootstrap/products.php?s=$1
RewriteRule ^bootstrap/rolex-watch.php http://www.mydomain.co.uk/bootstrap/rolex-watch [L]
RewriteRule ^bootstrap/scrap-gold.php http://www.mydomain.co.uk/bootstrap/scrap-gold [L]
RewriteRule ^bootstrap/eternity-ring.php http://www.mydomain.co.uk/bootstrap/eternity-ring [L]
RewriteRule ^bootstrap/engagement-ring.php http://www.mydomain.co.uk/bootstrap/engagement-ring [L]
RewriteRule ^bootstrap/wedding-ring.php http://www.mydomain.co.uk/bootstrap/wedding-ring [L]
RewriteRule ^bootstrap/diamond-ring.php http://www.mydomain.co.uk/bootstrap/diamond-ring [L]
RewriteRule ^bootstrap/inferno-diamonds.php http://www.mydomain.co.uk/bootstrap/inferno-diamonds [L]
RewriteRule ^bootstrap/radley-products.php http://www.mydomain.co.uk/bootstrap/radley-products [L]
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Respondido el 10 de Septiembre de 13 a las 00:09
0
Thanks Jon Lin, but it didn't quite work for me.
I seem to have bluffed my way to something that does work. Some entries I didn't need.
Is it written efficiently as I have no options defined?
RewriteEngine on
RewriteBase /bootstrap/
ErrorDocument 404 /bootstrap/404.php
ErrorDocument 403 /bootstrap/403.php
RewriteRule ^products/search/(.*)$ products.php?s=$1
RewriteRule ^products/(.*)/(.*)/(.*)$ products.php?f=$1&b=$2&t=$3
RewriteRule ^products/(.*)/(.*)$ products.php?f=$1&b=$2
RewriteRule ^products/(.*)$ products.php?f=$1
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Respondido el 10 de Septiembre de 13 a las 15:09
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas .htaccess or haz tu propia pregunta.