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"?

4
  • Check the RewriteRule syntax - it's the opposite. The first is "what to rewrite", the second is "the result of rewriting" Commented Apr 16, 2013 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 Commented Apr 16, 2013 at 22:00
  • This is like hacking, you are always better off using a simple PHP framework. Try CodeIgniter or CakePHP if you would like to give it a shot :) Commented Apr 16, 2013 at 22:21
  • See also stackoverflow.com/questions/8298787/… Commented Jul 18, 2015 at 15:53

3 Answers 3

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=

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

2 Comments

Language is ok.. I like it more with folder visible
@ЖеняТест Sorry, not sure what you mean.
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.

8 Comments

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.
Not Found The requested URL /en/things_to_visit was not found on this server. I don't understand why it doesn't work =(
Did a little test and it worked. Make sure that you can use mod_rewrite, and that /en/things_to_visit.php really exists.
hmmmm, may be it is not enabled.. I can't see it here: incinqueterre.com/1.php in phpinfo. I thought that "url_rewriter.tags" was enough... Will think tomorrow, now I have to leave
but with "hide index.php" it works, so its enabled... :/ ohhhh
|
0

Fixed by adding one line:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.