Un peu d'aide sur une expression mod_rewrite
-
03-07-2019 - |
Question
J'ai besoin d'une solution très rapide dans une expression mod_rewrite pour Drupal
RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
Mais je dois rediriger la valeur du sous-domaine dans get aussi, alors il me faut quelque chose qui donnera:
RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?subdomain=THE SUBDOMAIN HERE&q=$1 [L,QSA]
Je ne sais pas comment faire, aidez s'il vous plaît!
La solution
Réessayez, pour une raison quelconque, mon code ne s'affiche pas correctement.
RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{HTTP_HOST} ^(.*)\.mydomain\.com$
RewriteRule ^(.*) index.php?subdomain=%1&q=1 [L,QSA]
D'après certains messages de forum, j'ai trouvé ici .
Autres conseils
Vous n'avez pas vraiment besoin du sous-domaine dans la chaîne de requête.
Le sous-domaine se trouve en PHP dans $ _SERVER ['SERVER_NAME'].
Ladocumentation PHP indique:
'SERVER_NAME'
The name of the server host under which the
current script is executing. If the script
is running on a virtual host, this will be
the value defined for that virtual host.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow