htaccess mod_rewrite重写url的问题



我试图将url地址重定向到一个不错的url。不幸的是,经过几次尝试后,它仍然不能与这个htaccess工作,你能给我一些建议吗?

我htaccess

Options +FollowSymlinks
RewriteEngine On

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ /$1.html

RewriteCond %{REQUEST_URI} !^subdom/
RewriteCond %{REQUEST_URI} !^/subdom/
RewriteCond %{HTTP_HOST} ^(www.)?(.*).([^.]*).([^.]*)$
RewriteCond %{DOCUMENT_ROOT}/subdom/%2 -d
RewriteRule (.*) subdom/%2/$1 [DPI]

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^domains/[^/]+/(.+[^/])$ /$1/ [R]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^subdom/[^/]+/(.+[^/])$ /$1/ [R]

这个不行

RewriteCond %{QUERY_STRING} ^page=([^&]+)$
RewriteRule ^index.php$ %1? [R=301,L,NE]
RewriteRule ^([^/]+).html index.php?page=$1 [L,QSA]

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f

RewriteRule ^([^/]+)/([^/]+)/(.+)$ index.php?lang=$1&page=$2 [L,QSA]
RewriteRule ^([^/]+)/(.+)$ index.php?lang=$1 [L,QSA

我需要从中获利https://mypage.com/index.php?page=my-page和https://mypage.com/index.php?lang=en&页面=页面

这https://mypage.com/my-page/和https://mypage.com/en/my-page/

对于所示的示例,请尝试以下htaccess。这里添加了OP已经存在的规则(我删除了OP的规则RewriteCond %{REQUEST_URI} !^subdom/,因为REQUEST_URI变量总是从/开始,所以需要这个规则),并在其中添加了建议的规则。请确保在测试url之前清除浏览器缓存。

Options +FollowSymlinks
RewriteEngine ON
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ /$1.html
RewriteCond %{REQUEST_URI} !^/subdom/
RewriteCond %{HTTP_HOST} ^(www.)?(.*).([^.]*).([^.]*)$
RewriteCond %{DOCUMENT_ROOT}/subdom/%2 -d
RewriteRule (.*) subdom/%2/$1 [DPI]

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^domains/[^/]+/(.+[^/])$ /$1/ [R]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^subdom/[^/]+/(.+[^/])$ /$1/ [R]
####Newly added rules here....
RewriteCond %{QUERY_STRING} ^page=(.*)/?$ [NC]
RewriteRule ^index.php/?$ %1 [R=301,NC]
RewriteRule ^(.*)/?$ index.php?page=$1 [L]
RewriteCond %{QUERY_STRING} ^lang=([^&]*)&page=(.*)/?$ [NC]
RewriteRule ^index.php/?$ %1/%2 [R=301,NC]
RewriteRule ^([^/]*)/(.*)/?$ index.php?lang=$1&page=$2 [L]

相关内容

  • 没有找到相关文章

最新更新