Thursday, 15 March 2012

apache - .htaccess rule - check if the request is for a folder or file? -


I need to see the requested URL, and depending on what the request for file or directory is. . / P>

My URLs will look like this:

  • http://www.example.com/Services/Service-1 (directory, / Page / services / service1 / index.fp )
  • http://www.example.com/Services/Service-1/Feature-1/Sub-Feature < / Code> (a real file, service /pages/Services/Service-1/Feature-1/Sub-Feature.php )

    due to my lack Understanding the .htaccess (? It will require a RewriteCondition), I am currently stuck with each and every folder out of my directory structure as follows:

      RewriteRule ^ Service / Service -l / (K *) $ /pages/Services/Service-l/$lkphp RewriteRule ^ Service / Service -1 /pages/Services/Service-1/index.php RewriteRule ^ service / service -2 /(k*)$ / pages / services / service 2 / 1/1 Apeepeepi Riraitrebl ^ services / Service 2 / page / services / Service e -2 / index.php RewriteRule ^ services / (. *) $ /pages/Services/$1.php RewriteRule ^ services /pages/Services/index.php RewriteRule ^ testimonials /(k*)$ / pages / testimonials / $ 1 .php RewriteRule ^ testimonials / pages / testimonials / Index.php   

    No need to say, this is a real pain - at any time Add Ri folder, I have to mess with .htaccess.

    I know that should be a better way, but my google and stackoverflow searches have not done anything that works on working.

    If you guess it right, a rewrite is a requested uris file or directory, then it Can be used to confirm:

      # f is a file, a directory RewriteCond% {REQUEST_FILENAME} -f   

    .htaccess will be d:

      option on RewriteCond% -MultiViews RewriteEngine {REQUEST_FILENAME} D Rirekt rule (. +) / $ 1 / Indaks.afpeepi [Kyuesa, L] Riwratcond% {REQUEST_FILENAME} .php -f rewrite Rule (. +) / $ 1 If PPP [Kyuesa, L]   

    ED IT : If keeps your files page sub-directory, you must use the following code:

      Options Maltimiks Riwratangin on Riraitcond% {DOCUMENT_ROOT} / pages / $ 1-D rewrite (. +) /pages/$1/index.php [QSA, L] RewriteCond% {DOCUMENT_ROOT} / Pages / $ 1.php -f RewriteRule (. +) /pages/$1.php [QSA, L]    

No comments:

Post a Comment