skip to Main Content

I am using Opencart and I have some static pages also.
I don’t want to mess up opencart’s SEO options so is there a way to create clean URLs only for specific pages?

What I want is :

http://example.com/my-custom-page.php

to

http://example.com/my-custom-page

I am using standart htaccess file comes with opencart package

I have these lines:

RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^system/download/(.*) index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

2

Answers


  1. If you wanted to remove the .php extension in your url just use

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

    or this

    RewriteEngine  on
    RewriteRule ^(.*)$ $1.php
    

    If .html then you can do

    RewriteRule ^([^.]+)$ $1.html [NC,L]

    Login or Signup to reply.
  2. put the following code at main directory (root) .htaccess file :

    RewriteEngine on
    RewriteCond %{REQUEST_URI} my-custom-page.php
    
    # the line above to choose only my-custom-page.php and if you remove it
    # the code will remove all php pages extensions
    
    RewriteCond %{THE_REQUEST} /([^.]+).php [NC]
    RewriteRule ^ /%1 [L,R]
    

    The code will remove my-custom-page.php extension and it would be my-custom-page regardless of its directory

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search