我真的遇到了这个问题,并且不知道从哪里开始。
网址(重写):
http://www.website.com
http://www.website.com/au/
http://www.website.com/uk/
http://www.website.com/products
http://www.website.com/uk/products
http://www.website.com/au/products
实际网址:
http://www.website.com/index.php
http://www.website.com/index.php?co=au
http://www.website.com/index.php?co=uk
http://www.website.com/products.php
http://www.website.com/products.php?co=uk
http://www.website.com/products.php?co=au
有没有办法创造这个? (国家代码只有2个字母)
答案 0 :(得分:0)
以下解决方案是不灵活的解决方案,但它可以成为您灵感的源泉。
# This directive make effect to http://www.website.com -> http://www.website.com/index.php rule.
DirectoryIndex index.php index.html
RewriteEngine On
RewriteRule ^/(au|uk)/$ http://www.website.com/index.php?co=$1 [QSA,P,L]
RewriteRule ^/products$ http://www.website.com/products.php [QSA,P,L]
RewriteRule ^/uk/products$ http://www.website.com/products.php?co=uk [QSA,P,L]
如果您动态添加国家/地区代码,请尝试以下代码段。 这里有更多信息[https://httpd.apache.org/docs/current/rewrite/rewritemap.html]
RewriteEngine On
RewriteMap contry_code txt:conf/extra/contry_code.list
# ${contry_code:$1|au} some description is here; au is default value if non-mached
RewriteRule ^/([a-z][a-z])/$ http://www.website.com/index.php?co=${contry_code:$1|au} [QSA,P,L]
" contry_code.list"文件格式
# column1: using code for match, column2: return value
au au
uk uk
jp jp