0

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 
2
  • "middle of the extension" - what's an extension to you? Commented May 18, 2014 at 13:24
  • i want to remove the /themes/smooth/ part of the url Commented May 18, 2014 at 13:27

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Using a simple front-controller indeed makes this kind of thing easy to manage/modify (especially if rewrite rules are intimidating), the necessary rewrite rule should be in the answer. +1 anyway for managing to avoid the typical pitfall of allowing arbitrary file inclusion.
0

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] 

Comments