Reputation:
I have seen many question been asked about the .htaccess removal of extension and have found one that removes the .php from the extension by using this in the .htaccess files:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
My problem is that my extension is my-domain/themes/smooth/index.php and having that in the .htaccess file only shortens it to my-domain/themes/smooth/index and other pages like the contact us look like my-domain/themes/smooth/contact.
Is there any way of having the middle of the extension removed so that it look more like:
my-domain/contact
Upvotes: 0
Views: 63
Reputation: 785128
You can use this rule in root .htaccess to hide themes/smooth/
and .php
:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/themes/smooth/$1\.php -f [NC]
RewriteRule ^(.*)$ /themes/smooth/$1.php [L]
Upvotes: 0
Reputation: 760
Yes, there is, but frameworks such as Symphony , codeigniter etc will help you do that. If your looking for a simple implementation, then you can do a remap of the file names.
$uri = trim($_SERVER['REQUEST_URI'], '/'); $pages = array( 'contact' => 'path to contactus.php', 'services' => ' path to services.php' ); if ( in_array($uri, array_keys($pages))){ include $pages[$uri]; }
Ive not tested this code. In summary you have an index.php page and that page includes other pages.
Upvotes: 1