0

I have an older php website where i try to remove the .php Extension from php files getting accessed and showing in the browser but i have a problem.

I tried to add the last 2 lines to my .htaccess, saved it and checked the website again but the .php exstension is still there when i try to access parts of the website, anyone know why ?

This is my .htaccess file.

RewriteCond %{REQUEST_URI} ^(.+)\~s$
RewriteRule ^(.*) https://website.com/stats.php?url=$1 [L]
RewriteCond %{REQUEST_URI} ^(.+)\~q$
RewriteRule ^(.*) https://website.com/generate_qr.php?url=$1 [L]
RewriteCond %{REQUEST_URI} ^(.+)\~p$
RewriteRule ^(.*) https://website.com/preview_url.php?url=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) https://website.com/url_redirector.php?url=$1 [L]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [L]
Rizzzler
  • 193
  • 2
  • 12
  • Adding directives in .htaccess doesn’t magically remove the .php extension in your HTML source. To remove the file extension you need to actually remove the extension from the URL in the HTML source. The directives you’ve posted allow extensionless URLs to work (once you have physically removed the file extension on the URL in the HTML source). – MrWhite Jan 03 '22 at 12:24
  • Does this answer your question? [Mod Rewrite redirect URL with query string to pretty url](https://stackoverflow.com/questions/11629896/mod-rewrite-redirect-url-with-query-string-to-pretty-url) – Sumurai8 Jan 03 '22 at 12:41
  • Despite the odd name, we list that question as "How do I redirect an ugly url to a pretty url, then rewrite it back to the ugly url, without causing an infinite loop of redirects" in the mod-rewrite commonly asked questions – Sumurai8 Jan 03 '22 at 12:43
  • So what you mean is that i need to change href="register.php" to href="register" for example ? – Rizzzler Jan 03 '22 at 14:34
  • Yes, you need to manually update the `href` attribute. Note that if these old URLs (with `.php` extension) are indexed by search engines or linked to by third parties then you can implement a redirect to remove the `.php` extension in order to preserve SEO - but this is only once you have updated the URLs internally. – MrWhite Jan 03 '22 at 15:32

0 Answers0