J’ai lu beaucoup de questions et réponses ici, mais j’ai échoué à trouver une solution de travail. Je veux changer l’URL d’une syntaxe de lien plat à une requête “régulière”.
Comment puis-je obtenir de cela:
http://localhost/start/__developer/pages/12016652
pour ça:
http://localhost/start/__developer/pages/suche.php?objektnr=12016652
soit par htaccess soit par PHP? Ne tenez pas compte des curlies, s’il vous plaît. Merci d’avance pour ton aide!
À ce stade, j’essaie ceci:
Options +FollowSymLinks -MultiViews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteBase /start/__developer/immo-shg-v4/pages/ RewriteRule ^([0-9]+)$ suche.php?objektnr=$1 [QSA,L,NC]
Solution:
RewriteRule ^([0-9]+)$ suche.php?objektnr=$1 [L,NC,NE,R]
Le drapeau [R] force une redirection. http://httpd.apache.org/docs/2.2/rewrite/flags.html
Activez .htaccess via votre fichier httpd.conf, il n’est pas déjà activé et placez ces lignes dans le fichier .htaccess du dossier DOCUMENT_ROOT:
Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / # If the request is not for a valid file RewriteCond %{REQUEST_FILENAME} !-d # If the request is not for a valid directory RewriteCond %{REQUEST_FILENAME} !-f #This is your redirect rule RewriteCond %{QUERY_STRING} !(?:^|&)objektnr=([^&]*)(?:&|$) [NC] RewriteRule ^(start/__developer/pages/)([^/]*) $1suche.php?objektnr=$2 [L,NC,QSA]
Selon vos commentaires ci-dessous, un autre RewriteRule comme celui-ci:
# If the request is not for a valid file RewriteCond %{REQUEST_FILENAME} !-d # If the request is not for a valid directory RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{QUERY_STRING} !(?:^|&)objektnr=([^&]*)(?:&|$) [NC] #This is your modified redirect rule RewriteRule ^(start/__developer/immo-shg-v4/pages/)([^/]*) $1suche.php?objektnr=$2 [L,NC,QSA]