更改可见网址,但保持旧的重定向

时间:2015-09-24 15:17:13

标签: php .htaccess

我有静态网页。它包含3种语言。每种语言都是单独的文件夹所以我有文件夹eng,de和hr。在每个文件夹中我都有index.php,exapmle1.php,example2.php等。我有.htaccess,我有:

RewriteEngine on
RewriteBase  /
redirect 301 /index.php http://www.example.com/eng/

所以我需要的是当我输入文件夹时删除文件夹。 我有:

  http://www.example.com/eng/index.php

 http://www.example.com/de/index.php

我需要:

  http://www.example.com/index.php

我尝试删除eng但是当我点击语言选择器时我需要能够输入另一个文件夹。

 RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+eng/([^\s]+) [NC]

有人可以给我一些提示吗?

编辑:

所以现在我有网址:

example.com/hr/index.php
example.com/eng/index.php
example.com/de/index.php
example.com/hr/aboutus.php
example.com/eng/aboutus.php
example.com/de/aboutus.php

所以你可以猜到我的文件结构中有3个文件夹。我有eng,de和hr文件夹,在里面我有一些名为index.php和aboutus.php的文件。

我有html' a'导致hr / index.php,eng / aboutus.php等文件的元素。

我需要更改网址,它应显示为:

  example.com/hr/index.php

  example.com/naslovna


  example.com/eng/index.php

  example.com/home

  example.com/eng/aboutus.php

  example.com/aboutus

1 个答案:

答案 0 :(得分:0)

毕竟我发现这有效:

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteRule ^page-name/?$   index.php?page=page-name
相关问题