繁体   English   中英

htaccess mod_rewrite 重写 url 的问题

[英]htaccess mod_rewrite problem with rewriting 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

I need make from this https://mypage.com/index.php?page=my-page and https://mypage.com/index.php?lang=en&page=my-page

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]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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