mod_rewrite pour rediriger /index.whats to / ne fonctionne pas
-
06-07-2019 - |
Question
Je souhaite rediriger toutes les demandes d'index.html | php | php5 vers http: //www.domain .co.uk / en utilisant mod_rewrite et j'ai copié le code d'un livre sur l'optimisation de moteur de recherche avec PHP, puis ajouté à l'option php5, mais cela ne fonctionne pas. Ceci est mon fichier .htaccess complet:
RewriteEngine On
#translate any .html ending into .php5
RewriteRule ^(.*)\.html$ /$1\.php5
RewriteCond %{THE_REQUEST} ^GET\ .*/index\.(php5|php|html)\HTTP
RewriteRule ^(.*)index\.(php5|php|html)$ /$1 [R=301,L]
#change / for ?
RewriteRule ^(.*)\.html/(.*)$ /$1\.html?$2
#strip .html from search res page
RewriteRule ^(.*)search/(.*)$ /$1search_results\.html/search=$2
#translate product details link from search res page
RewriteRule ^products/(.*)/(.*)/(.*)$ /product_details.php5?category=$1&title=$2&id=$3 [L]
#Translate products/psorisis/chamomile-skin-cream-P[x] to productview.php5?id=1
RewriteRule ^products/.*-P([0-9]+) /productview.php5?id=$1 [L]
Je ne sais pas ce qui ne va pas avec cela, et le reste marche bien et dandy. Quelqu'un a des idées?
La solution
Je pense que c'est parce que votre RerwriteCond se termine par \ HTTP
.
Changez-le en:
RewriteCond %{THE_REQUEST} ^GET\ .*/index\.(php5|php|html)
RewriteRule ^(.*)index\.(php5|php|html)$ /$1 [R=301,L]
Si vous voulez faire correspondre le HTTP de THE_REQUEST, mettez un espace là-bas
RewriteCond %{THE_REQUEST} ^GET\ .*/index\.(php5|php|html)\ HTTP
RewriteRule ^(.*)index\.(php5|php|html)$ /$1 [R=301,L]
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow