简体   繁体   中英

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. PHP changes a translation file when url has that /en/ after the domain.

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. I still want to find all the files and folders even when the /en/ part is there.

For example:

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

shows the image from here

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

But it has to keep the /en/ part in the URL, so the language won't change.

I have this in my .htaccess file:

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. :/

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? Thanks. :)

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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