简体   繁体   中英

.htaccess if path (folder) doesn't exist request another path

By adding the language to my website i'm facing a problem. Becouse i don't want to change all my urls from all my templates but i want to keep the language into my url i need to modyfy the .htaccess .

Basicly the problem is as folows: - To keep the language in url i have to change the site url: ex:

without language: http://www.mysite.com/some/other/vars SITE_URL : http://www.mysite.com

with language: http://www.mysite.com/cn/some/other/vars changed SITE_URL : http://www.mysite.com/cn

when i request for css file SITE_URL/my_style/style.css , obiously the css will not be found in 2'nd case becouse is not in the folder cn/

How i can modyfy the .htaccess to change the requested path if the path is :

http://www.mysite.com/cn

http://www.mysite.com/es

http://www.mysite.com/fr

Originaly htaccess content is:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

Options All -Indexes 
Options All -Indexes 
Options All -Indexes

Thanks..it should be simple...but i can't do it since 2 hours.

EDIT:

All i want is: If a request is made at: www.mysite.com/cn/any/thing/else/style.css (in this case css file will not exist), make the request at: www.mysite.com/any/thing/else/style.css

Was a long day with no progress ...haha. it happends.

I suggest to fix the issue by requesting correct url! That just would be right.

However this should work

RewriteRule ^(cn|es|fr)/my_style/(.+)$ /my_style/$2 [L]

Add this to the htaccess files that you have in your cn/es/fr folders, preferably before any rules that you may have there:

RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/$1 -d
RewriteRule ^(.*)$ /$1 [L]

This should make it so a request for /my_style/style.css from within the cn folder will serve the one from the document root.

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