I'm trying to simplify the URLs using rewrite condtions and rules on my local WAMP website. For example I would like to have /ProjetSyntheseFAC/mammiferes instead of /ProjetSyntheseFAC/pages/animaux/mammiferes.php.

I have to remove folders from the URL and delete the ".php" from the end. Everything I've tried either does not work or produces an internal server error.

Here is my folder hierarchy:

- index.php
- .htaccess
- pages: 
     - animaux:
           - mammiferes.php
           - oiseaux.php
           - reptiles.php
     - infos:
           - access.php
           - contact.php
           - plan.php
     - spectacle: 
           - reserverPlace.php
           - spectacle.php`

Here is what I tried last:

RewriteEngine On
RewriteRule ^mammiferes$ /pages/animaux/mammiferes.php 


RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteCond %{REQUEST_URI} /(.+)
RewriteRule !\.[a-z0-4]{2,4}$ /pages/animaux/%1.php [NC,L]
RewriteRule (.*) /pages/animaux/$1 [L]
  • It looks like your rewrite rules may need to include the project folder in them. Something like RewriteRule ^ProjetSyntheseFAC/mammiferes$ /ProjetSyntheseFAC/pages/animaux/mammiferes.php or you might be able to use your existing rewrite rules by setting RewriteBase /ProjetSyntheseFAC/ just after turning on the rewrite engine. – Stephen Ostermiller Dec 12 '17 at 12:23
  • How does your /ProjectSyntheseFAC subdirectory fit into your "folder hierarchy"? Is this the equivalent of your Project: folder in your hierarchy? Or, what is the relevance of Project: in your hierarchy, as it appears to be at the same level as pages:? What is the document root? – MrWhite Dec 12 '17 at 18:57
  • Aside: Are you intending to later transfer this to a "live" site? What will happen to the "project" subdirectory then? – MrWhite Dec 12 '17 at 19:17
  • Cross-site post: stackoverflow.com/questions/47761442/… – MrWhite Dec 12 '17 at 23:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.