Arama Yap Mesaj Submit
Request a Callback
+90
X
X

Select Your Currency

Turkish Lira $ US Dollar Euro
X
X

Select Your Currency

Turkish Lira $ US Dollar Euro

Contact Us

Location Halkali merkez neighborhood fatih st ozgur apt no 46 , Kucukcekmece , Istanbul , 34303 , TR
Clean URL and Internal Rewrite

How to Remove `.php` and `.html` Extensions from URLs

Removing the extension requires two separate operations: when a user or search engine visits the `.php` URL, an external 301 redirect is issued to the clean URL; the clean URL request is then internally rewritten to the actual `.php` file. If these two steps are not separated, infinite redirects and duplicate URLs may occur.

Remove .phpClean URLTHE_REQUESTInternal RewriteTrailing Slash
Apache/LiteSpeed Diagnostics
/product.php -> /product
Internal rewrite: /product -> /product.php
ERR_TOO_MANY_REDIRECTS
404 Not Found
01Verify file and document root
02Take a backup and read the error log
03Separate server and application context
04Verify live result with curl
01
Safe technical approach

Removing PHP and HTML Extensions How to analyze?

Removing the extension requires two separate operations: when a user or search engine visits the `.php` URL, an external 301 redirect is issued to the clean URL; the clean URL request is then internally rewritten to the actual `.php` file. If these two steps are not separated, infinite redirects and duplicate URLs may occur.

01

Determine server type

Do not expect a `.htaccess` result without reserving the Apache, LiteSpeed, Plesk proxy or NGINX-only structure.

02

Get backup and logs

Back up the current file with the date; Find the directive and line in the Apache/LiteSpeed error log.

03

Change one rule

Do not change redirect, rewrite, header and access rules all at the same time.

04

Test from outside

Measure the status, Location, Content-Type and redirect number with curl and check the cache layers separately.

Do not apply a broad, unconditional rewrite to all URLs to remove extensions.

02
Live problem dictionary

Apache, redirect and access messages

01kritik

Infinite redirect

Meaning: Internal rewrite enters external redirect condition again.

Possible cause: No differentiation is made using REQUEST_URI.

02warning

Temiz URL 404

Meaning: The corresponding `.php` file is not being checked.

Possible cause: Wrong file path or subdirectory.

03warning

CSS and images are broken

Meaning: Relative asset paths are resolved according to the new URL depth.

Possible cause: Base path/relative URL.

04warning

Query string kayboldu

Meaning: The rewrite/redirect query behavior is incorrect.

Possible cause: QSA/QSD or `?` in target.

05warning

A real directory was rewritten

Meaning: No directory exception.

Possible cause: The `!-d` condition is missing.

06warning

Incorrect target in subfolder

Meaning: Being rewritten to the root path.

Possible cause: RewriteBase/relative substitution.

07warning

WordPress route conflict

Meaning: The file extension rule conflicts with the front controller.

Possible cause: Rule order.

08bilgi

File not found in MVC.

Meaning: The clean URL should go to the router, not a physical `.php` file.

Possible cause: Front-controller architecture.

No records matching this expression were found.

03
Copiable controls

curl, Apache log and file tests

Two URL tests

for u in https://example.com/product.php https://example.com/product; do curl -sS -o /dev/null -w "$u -> %{http_code} %{url_effective} redirects:%{num_redirects}\n" -L "$u"; done

Compares the results of URLs with and without extensions.

Location zinciri

curl -sIL --max-redirs 10 'https://example.com/product.php?id=42' | grep -iE '^HTTP|^location:'

Shows the redirect chain with the query string.

Actual PHP files

find . -maxdepth 2 -type f -name '*.php' -printf '%P\n' 2>/dev/null | sort | head -n 100

Lists PHP files that may be subject to rewrite.

Rule order

grep -nE 'THE_REQUEST|REQUEST_FILENAME|RewriteRule|RewriteCond' .htaccess

Shows the extension and front-controller rules with their order numbers.

Asset control

curl -sL https://example.com/product | grep -ioE '(src|href)=["'"'][^"'"']+' | head -n 40

Shows the asset paths on the clean URL page.

Canonical control

curl -sL https://example.com/product | grep -ioE '<link[^>]+rel=["'"']canonical["'"'][^>]*>' | head -n 1

Checks if the canonical URL shows an extensionless target.

04
Correct and incorrect structure

.htaccess rule comparisons

Internal rewrite only

Risky / Incorrect
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php [L]
Right Approach
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php(?:[\s?]) [NC]
RewriteRule ^(.+?)\.php$ /$1 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [END]

Real file exception

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

HTML extension

Risky / Incorrect
RewriteRule ^(.+)\.html$ $1 [L]
Right Approach
RewriteCond %{THE_REQUEST} \s/+(.+?)\.html(?:[\s?]) [NC]
RewriteRule ^(.+?)\.html$ /$1 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+?)/?$ $1.html [END]

MVC front controller

Risky / Incorrect
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php [L]
Right Approach
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L,QSA]
05
Application by infrastructure

Apache, cPanel, Plesk, LiteSpeed and applications

Static PHP Pages

Each clean URL can be mapped to a physical `.php` file.

  • Separate the external redirect using THE_REQUEST.
  • Use a real file/directory exception.
  • Update canonical and internal links to clean URLs.

MVC / Custom PHP / WISECP

In a front-controller architecture, use the router instead of removing physical extensions.

  • Do not break the WISECP route structure.
  • Keep the index.php front-controller rule as a single source.
  • Add selective 301 redirects for old `.php` URLs.

WordPress / NGINX / LiteSpeed

WordPress already generates clean URLs; custom file rules must come before the managed block.

  • On an NGINX-only system, use `try_files` and location blocks.
  • Test Apache-compatible rules on LiteSpeed.
  • Verify the results of the two URLs after cache.
Incorrect interventions

Absolutely don't

  • Do not apply a broad, unconditional rewrite to all URLs to remove extensions.
  • Do not run internal rewrite with external 301 under the same condition.
  • Do not assume physical `.php` files exist in an MVC project.
  • Do not leave canonical and internal links on old extension URLs.
Post-procedure check

Verify the solution

  • The URL with extension redirects to the clean URL with a single 301.
  • The clean URL returns 200 and no redirect loop occurs.
  • Query strings, asset paths, and form action paths are preserved.
  • The sitemap, canonical tags, and internal links use only clean URLs.
06
Internal SEO content set

Related .htaccess solutions

07
primary sources

Apache, WordPress and panel documentation

08
Frequently asked questions

Removing PHP and HTML Extensions Curiosities about

Does the PHP and HTML extension removal rule work on NGINX?

No. NGINX does not read `.htaccess` files. The rule must be translated to a `server` or `location` configuration.

Is Apache restart required for .htaccess changes?

Usually not; Apache evaluates the `.htaccess` file on each request. However, a reload or restart is required for VirtualHost, module, or AllowOverride changes.

What should be done before editing the file?

A dated backup of the existing file should be taken, the active document root verified, and the change tested on staging or during low-traffic periods.

Where is the file located in Plesk with cPanel?

In cPanel it is usually inside `public_html`, in Plesk inside `httpdocs`; addon domains and subdomains may have a different document root.

Does LiteSpeed support `.htaccess` rules?

LiteSpeed supports most rules through Apache compatibility; some module and handler behaviors may differ.

Where should I look first in case of a 500 error?

Full directive and line record in Apache/LiteSpeed error log. The file should be restored according to the log instead of being deleted randomly.

Can these codes be added directly to the live site?

Domain should not be added directly without verifying domain, document root, proxy, WordPress, and server structure. Examples should be adapted and tested.

EKA SOFTWARE AND INFORMATION SYSTEMS

Let's edit .htaccess and Apache rules without making the site inaccessible

We examine redirection, rewrite, CORS, access and 500 errors with logs in cPanel, Plesk, LiteSpeed, WordPress, custom PHP and WISECP structures.

Get Server SupportWhatsApp
Top