简体   繁体   English

htaccess忽略URL的特定部分

[英]htaccess to ignore specific part of the URL

I'm trying to change language of a website to english when URL has /en/ after the domain. 当域名后有/ en /时,我正在尝试将网站的语言更改为英语。 PHP changes a translation file when url has that /en/ after the domain. 当url在域后带有/ en /时,PHP会更改翻译文件。

My system adds that /en/ part to all links, even CSS-file's URL etc. It works ok, but I cannot reach any files when that part is in the URL. 我的系统将/ en /部分添加到所有链接,甚至包括CSS文件的URL等。它都可以正常运行,但是当该部分位于URL中时,我无法访问任何文件。 I still want to find all the files and folders even when the /en/ part is there. 我仍然想找到所有文件和文件夹,即使/ en /部分在那里。

For example: 例如:

http://domain.com/en/images/image.png http://domain.com/en/images/image.png

shows the image from here 从这里显示图像

http://domain.com/images/image.png http://domain.com/images/image.png

But it has to keep the /en/ part in the URL, so the language won't change. 但是它必须在URL中保留/ en /部分,因此语言不会改变。

I have this in my .htaccess file: 我的.htaccess文件中有此文件:

RewriteEngine on
Options +FollowSymlinks
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

This redirects the URL, but it removes the /en/ part. 这将重定向URL,但会删除/ en /部分。 :/ :/

RedirectMatch ^/en/(.*) /$1

So is it even possible to redirect and leave the original url? 因此,甚至可以重定向并保留原始网址吗? If not, is it possible to redirect (and change URL) only when it is existing folder or a file? 如果不是,是否只有在现有文件夹或文件存在的情况下才可以重定向(和更改URL)? Thanks. 谢谢。 :) :)

用以下内容替换您的RedirectMatch行:

RewriteRule ^en/([^.]+\.(?:jpe?g|gif|bmp|png|tiff|css|js))$ /$1 [L,NC]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM