How to create a .htaccess file?

I am trying to create .htaccess , but we have some difficulties.

Here are examples of what I need, remembering that everything should be on the same URL.

1) Whenever a user accesses a website, add /home/ to the end of the URL.

 Before: http://app.meusite.com/ After: http://app.meusite.com/home/ 

2) I want all urls to be removed .php .

 Before: http://app.meusite.com/login.php After: http://app.meusite.com/login/ 

3) I want all urls to be as follows:

Before:

 http://app.meusite.com/usuario-adicionar.php http://app.meusite.com/usuario-editar.php http://app.meusite.com/usuario-excluir.php 

After:

 http://app.meusite.com/usuario/adicionar/ http://app.meusite.com/usuario/editar/ http://app.meusite.com/usuario/excluir/ 

Just pay attention to the note ...

Since the entire site will be multilingual, everyone should accept a settings page that will receive LANG = LANGUAGE (Example: lang = en_US ).

Then, all of the above URLs should also accept GET vestments and would like to stay as follows:

 http://app.meusite.com/index.php?lang=en_US http://app.meusite.com/home/en_US/ http://app.meusite.com/login.php?lang=en_US http://app.meusite.com/login/en_US/ http://app.meusite.com/usuario-adicionar.php?lang=en_US http://app.meusite.com/usuario/adicionar/en_US/ http://app.meusite.com/usuario-editar.php?lang=en_US http://app.meusite.com/usuario/editar/en_US/ http://app.meusite.com/usuario-excluir.php?lang=en_US http://app.meusite.com/usuario/excluir/en_US/ 

I hope he understands my question. And can you help me do this?

Below is my attempt:

 Options -MultiViews Options +FollowSymLinks RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !(.*)/$ RewriteRule ^home\/?(.*)\/?$ index.php?lang=$1 [L] RewriteRule ^([^/]*)\/?(.*)\/?$ $1.php?lang=$2 [L] RewriteRule ^([^/]*)\/([^/]*)\/([^/]*)\/?$ $1-$2.php?lang=$3 [L] 
+4
source share
1 answer

Before deleting the file extension, you first need to make sure that MultiViews is enabled. In addition, you should include the canonical meta tag in the HTML chapter, depicting what you want the link to look like if you were worried that search engines might index your pages as duplicate content. It should look like this:

 <link rel="canonical" href="http://example.com/post/post-title/"> 

To remove the file extension and add a slash, you need this bit of code.

 #turn on Multiviews if not already turned on Options +MultiViews #takes off the .php RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/$ $1.php RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php #adds the trailing slash RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$ RewriteRule (.*)$ /$1/ [R=301,L] 

I found out about it here and successfully used the code in my .htaccess files. I have not yet been able to figure out how to handle the multilingual aspect of your question. I have never had this problem. But I will do some research when I sleep more and come back here if I find anything useful. It seems to me that the answer is looking in my face.

Once you have fixed this, do not forget to do 301 redirects.

0
source

All Articles