.htaccess , compitable

# Apache Rewrite Rules
 <IfModule mod_rewrite.c>
  Options +FollowSymLinks
  RewriteEngine On
  RewriteBase /

#redirect /file.php to /file
  RewriteCond %{THE_REQUEST} \s/([^.]+)\.php [NC]
  RewriteRule ^ /%1 [NE,L,R]
# now we will internally map /file to /file.php
  RewriteCond %{REQUEST_FILENAME}.php -f
  RewriteRule ^(.*)/?$ /$1.php  [L]

# End of Apache Rewrite Rules

I want to ask if this code works properly when I build on .htaccess, and if there are any other suggestions so I can use it?, I tried but nothing happened, can you help me?

Do you want to remove .php?

yes i wan to remove .php and .html

Options +FollowSymLinks
RewriteEngine On

# Remove .html extension
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)\.html$ /$1 [NC,L,R]

# Remove .php extension
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)\.php$ /$1 [NC,L,R]

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

I’ve used the suggested code, but after I delete the chace in the browser and try to open the URL the extension .html still visible

Make sure to access the url without the .html

Could you please share your Website’s link?

https://www.7Elohim.my.id

Working fine for me. Keep in mind you should remove .html from the redirect url too.

But why does my browser still have .html and .php?

Here is a modified version of it try this.

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

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

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

RewriteCond %{THE_REQUEST} \s/([^.]+)\.php [NC]
RewriteRule ^ /%1 [NE,L,R]

RewriteCond %{THE_REQUEST} \s/([^.]+)\.html [NC]
RewriteRule ^ /%1 [NE,L,R]

Can you see my web, there seems to be an error that occurred, so it can’t go directly to the next page

Working fine for me, what’s the error message you are getting?

what’s wrong with my browser :frowning:

Whether you have deleted chace and cookies

try this now

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

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

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

# Redirect /file.php to /file
RewriteCond %{THE_REQUEST} \s/([^.]+).php [NC]
RewriteRule ^ /%1 [NE,L,R]

# Redirect /file.html to /file
RewriteCond %{THE_REQUEST} \s/([^.]+).html [NC]
RewriteRule ^ /%1 [NE,L,R]

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.