2

I have this URL

http://localhost:8888/dochealth/child-doc?cat=doctor

and wanted to replace it with .htaccess REGEX So it becomes

http://localhost:8888/dochealth/child-doc/doctor

so far I have tried this REGEX but it doesn't work

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
RewriteRule ^child-doc/([0-9a-zA-Z_-]+) child-doc?cat=$1 [NC,L]
</IfModule>

1 Answer 1

2

Have it this way:

Options -MultiViews
RewriteEngine On

RewriteRule ^child-doc/([\w-]+) child-doc.php?cat=$1 [NC,QSA,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

Changes are:

  1. Move .php extension handler rule to the bottom
  2. Use child-doc.php in other rules
  3. Additional of QSA (query string append) in the same rule
  4. Turning off MultiViews to disable content negotiations service of Apache
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.