Ignore first variable on link using HTACCESS permalinks

Deadly 提交于 2020-01-17 08:40:27

问题


I am using this htaccess rules to create permalinks on the root folder of a domain :

Options +FollowSymlinks
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* ?url=$0 [L,QSA]

Now i want to use the same rules but on a folder inside this website because i want to make it in two different languages. So if i create a folder: example.com/en/ , i want this conditions to apply same as in the root folder for calling links as below but ignoring the first get variable:

example.com/about-us/ || example.com/en/about-us/


回答1:


Try this .htaccess with an additional rule:

Options +FollowSymlinks
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^[a-z]{2}/(.*)$ ?url=$1 [L,QSA]

RewriteRule .* ?url=$0 [L,QSA]


来源:https://stackoverflow.com/questions/43216671/ignore-first-variable-on-link-using-htaccess-permalinks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!