繁体   English   中英

使用.htaccess的网址重定向问题

[英]url redirection issue using .htaccess

以下是我需要使用.htaccess进行转换的东西

  1. 如果url为sample.xxx.com,则意味着我需要将其转换为www.xxx.com/domain/sample

  2. 我的网址是sample.xxx.com/category/34/electonics.html意味着我需要将其转换为www.xxx.com/domain/sample/category/34/electronics.html

3.再次转换这些东西后,我需要将请求建立到必要的页面

我有以下规则

RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteCond %1 !^(www|ftp|mail)$ [NC]
RewriteRule ^(.*)$ http://www.example.com/domain/%1/$1 [P,QSA]

RewriteRule ^domain/([a-zA-Z0-9_\-]+)$ index.php?domain=$1 [Nc,L]
RewriteRule ^domain/([a-zA-Z0-9_\-]+)/$ index.php?domain=$1 [Nc,L]
RewriteRule ^domain/([a-zA-Z0-9_\-]+)/news/([a-zA-Z0-9_\-]+)/([0-9]+)_([0-9]+)/([a-zA-Z0-9_\-]+)\.html$ news.php?domain=$1&category=$4&news=$3 [Nc,L]
RewriteRule ^domain/([a-zA-Z0-9_\-]+)/category/([0-9]+)/([a-zA-Z0-9_\-]+)\.html$ category.php?domain=$1&category=$2 [Nc,L]
RewriteRule ^domain/([a-zA-Z0-9_\-]+)/gallery/([0-9]+)/([a-zA-Z0-9_\-]+)\.html$ gallery.php?domain=$1&category=$2 [Nc,L]
RewriteRule ^domain/([a-zA-Z0-9_\-]+)/video/([0-9]+)/([a-zA-Z0-9_\-]+)\.html$ video.php?domain=$1&category=$2 [Nc,L]

但是失败了

如果我将第4行更改为

RewriteRule ^(.*)$ http://www.example.com/domain/%1/$1 [NC,QSA]

表示它将正常工作,但浏览器会显示重构的网址。

任何人都可以发现我的错误。

如果将http://保留在目标URI中,则它的确会完全重定向。

尝试这个:

RewriteEngine On

RewriteCond %{HTTP_HOST} !^(www|ftp|mail)\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$ [NC]
RewriteRule ^((?!domain/).*)$ domain/%1/$1 [L,NC]

RewriteRule ^domain/([\w-]+)/news/([\w-]+)/([0-9]+)_([0-9]+)/([\w-]+)\.html$ news.php?domain=$1&category=$4&news=$3 [NC,L]
RewriteRule ^domain/([\w-]+)/category/([0-9]+)/([\w-]+)\.html$ category.php?domain=$1&category=$2 [NC,L]
RewriteRule ^domain/([\w-]+)/gallery/([0-9]+)/([\w-]+)\.html$ gallery.php?domain=$1&category=$2 [NC,L]
RewriteRule ^domain/([\w-]+)/video/([0-9]+)/([\w-]+)\.html$ video.php?domain=$1&category=$2 [NC,L]

RewriteRule ^domain/(.+)/?$ index.php?domain=$1 [NC,L]

暂无
暂无

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

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