2010-09-27 6 views
1

Disons que j'ai un dossier principal dans mon site web nommé « test » qui contient un fichier index.php de www.example.com/test/index.phpPHP redirigeant tous les chemins vers un certain fichier php?

Comment puis-je faire en sorte que toute URL contenant ce chemin "www.example.com/test" redirige vers "www.example.com/test/index.php" et maintenez toujours le premier chemin de requête

par exemple:

www.example.com/test/User  redirects to www.example.com/test/index.php 
www.example.com/test/User/2  redirects to www.example.com/test/index.php 
www.example.com/test/Account redirects to www.example.com/test/index.php 
www.example.com/test/Account/5 redirects to www.example.com/test/index.php 

Répondre

3

Utiliser Apache Rewrite module . Par exemple, dans une configuration virtuelle hôtes, ou dans le fichier .htaccess d'un répertoire, vous pouvez écrire ceci:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} -s [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [NC,L] 
RewriteRule ^.*$ index.php [NC,L] 

Cela ferait une URL qui a approché ce répertoire rediriger vers index.php mais il ne serait pas changer l'URL du script analyse


Voici quelques Godaddy.com docs sur l'utilisation réécritures dans leur environnement d'hébergement:

+0

Merci, je me sers de GoDaddy, toute idée où je peux trouver "httpd.config"? – aryaxt

Questions connexes