0

I know there are many topics. I tried them many times, but it doesn't work.

What do I want?

Instead of example.com/en/file.php, users see only example.com/en/file.

My .htaccess file:

DirectoryIndex index.php index.html

RewriteEngine on
*RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ /$1.php*


ErrorDocument 404 /index.php

RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^ru\/index\.php$ "http\:\/\/example\.com\/ru\/" [R=301,L]

RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^en\/index\.php$ "http\:\/\/example\.com\/en\/" [R=301,L]

etc. for every language

  1. What do I have to add to hide extensions?

  2. After it works, should I use links between pages as "file.php" or only "file"?

Community
  • 1
  • 1
  • Check the `RewriteRule` syntax - it's the opposite. The first is "what to rewrite", the second is "the result of rewriting" – zerkms Apr 16 '13 at 21:50
  • 3
    This has to be the most asked question that I have seen on SO, it does not hurt to perform a search prior to posting – Daryl Gill Apr 16 '13 at 22:00
  • This is like hacking, you are always better off using a simple PHP framework. Try [CodeIgniter](http://ellislab.com/codeigniter) or [CakePHP](http://cakephp.org/) if you would like to give it a shot :) – Chibueze Opata Apr 16 '13 at 22:21
  • See also http://stackoverflow.com/questions/8298787/using-htaccess-never-show-index-php/31492764#31492764 – cssyphus Jul 18 '15 at 15:53

3 Answers3

1

Perhaps something like this. Modify as you see fit for more specific pattern matching.

RewriteRule ^(?:(.*)/)?(.*)$ $2.php?lang=$1

Rewrites:

/en/fun => /fun.php?lang=en

/ru/fun => /fun.php?lang=ru

/fun => /fun.php?lang=

showdev
  • 28,454
  • 37
  • 55
  • 73
0
DirectoryIndex index.php index.html    

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

In your links, don't use extensions.

Marcelo Pascual
  • 810
  • 8
  • 20
  • adding: RewriteEngine on RewriteRule ^(.+)$ $1.php [L] //doesn't works: The requested URL /q_insert_city_image was not found on this server. Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request. – Michael Moor Apr 16 '13 at 22:02
  • Not Found The requested URL /en/things_to_visit was not found on this server. I don't understand why it doesn't work =( – Michael Moor Apr 16 '13 at 22:17
  • Did a little test and it worked. Make sure that you can use `mod_rewrite`, and that `/en/things_to_visit.php` really exists. – Marcelo Pascual Apr 16 '13 at 23:59
  • hmmmm, may be it is not enabled.. I can't see it here: http://www.incinqueterre.com/1.php in phpinfo. I thought that "url_rewriter.tags" was enough... Will think tomorrow, now I have to leave – Michael Moor Apr 17 '13 at 06:26
  • but with "hide index.php" it works, so its enabled... :/ ohhhh – Michael Moor Apr 17 '13 at 06:28
  • I tried this: RewriteRule ^(.*)\.p$ $1.php [L,QSA] and it works from .p to .php but without extension no +_+ – Michael Moor Apr 17 '13 at 06:37
  • Sorry for my spam, just checked on other host and your code works! So, it's a problem of my host... I'll send them a ticket now – Michael Moor Apr 17 '13 at 07:05
  • Yes, thank you ;) By adding 1 line: Options -Multiviews // it now works on my host too, that was a problem :) – Michael Moor Apr 18 '13 at 10:10
0

Fixed by adding one line:

RewriteEngine on
**Options -Multiviews**
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$      $1.php     [L,QSA]
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131