0

After looking a lot into stackoverflow i'm not able to figure it out. I have a website with the following structure

index.php
contact.php
about.html
forum(dir)
   - index.php
   - thread.php

What i want my htaccess to do

  • Remove .php & .html extension, eg: when you visit contact page the url should be www.domain.com/contact/ & www.domain.com/about/
  • When the user visits the forum the url should be www.domain.com/forum/thread/10004000/ instead of www.domain.com/forum/thread?id=10004000

I'm not sure how to figure it out. I was able to remove the extensions but failed in the / "forward slash" part

This is my .htaccess part

RewriteEngine on 

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

2 Answers2

0

Try below code to remove php extention , same for html you can added

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteRule ^forum/thread/(.+) /forum/thread?id=$1 [L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]
Shantun Parmar
  • 432
  • 2
  • 13
0

try this demo mod_rewrite link

Suman
  • 103
  • 6