。htaccess条件语句

问题描述 投票:0回答:1

我想使用通配符子域将我的网址重写为更多的seo网址,但是我无法编写htaccess条件并希望获得一些帮助。

我有这个网址:

http://learntipsandtricks.com/blog/c/magento

我想改写为:

http://magento.learntipsandtricks.com/

更改分页链接:

http://learntipsandtricks.com/blog/92/magento/3

至:

http://magento.learntipsandtricks.com/p-92-3

最后更改文章网址:

http://learntipsandtricks.com/blog/magento/114/magento-index-management-Cannot-initialize-the-indexer-process

至:

http://magento.learntipsandtricks.com/114-magento-index-management-Cannot-initialize-the-indexer-process

我写了这个:

RewriteCond %{HTTP_HOST} !^www\.(.+)$ [NC]
RewriteCond %{HTTP_HOST} (.+)\.learntipsandtricks\.com\/p\-(\d+)\-(d+) [NC]
RewriteRule ^(.*)$ http://learntipsandtricks.com/blog/%2/%1/%3/$1 [P]

RewriteCond %{HTTP_HOST} !^www\.(.+)$ [NC]
RewriteCond %{HTTP_HOST} (.+)\.learntipsandtricks\.com\/(\d+)\-(.*) [NC]
RewriteRule ^(.*)$ http://learntipsandtricks.com/blog/%1/%2/%3/$1 [P]

RewriteCond %{HTTP_HOST} !^www\.(.+)$ [NC]
RewriteCond %{HTTP_HOST} (.+)\.learntipsandtricks\.com [NC]
RewriteRule ^(.*)$ http://learntipsandtricks.com/blog/c/%1/$1 [P]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php/$1 [L]

上面的代码不起作用。是否可以在htaccess中使用if else来检查所有类型的url并进行相应的重写?

编辑:

RewriteCond %{HTTP_HOST} !^www\.(.+)$ [NC]
RewriteCond %{HTTP_HOST} (.+)\.learntipsandtricks\.com [NC]
RewriteCond %{REQUEST_URI} ^/p-(\d+)-(\d+)$ [NC]
RewriteRule ^(.*)$ http://learntipsandtricks.com/blog/%1/[first part of sub-domain]/%2/$1 [P]

如何在这里获得子域的第一部分。

谢谢。

.htaccess seo subdomain wildcard-subdomain
1个回答
1
投票

HTTP_HOST不包含URL路径。如果要与URL路径匹配,请使用REQUEST_URI代替

RewriteCond %{REQUEST_URI} ^/p-(\d+)-(\d+)$

例如。

来自RewriteCond Directive

  • RewriteCond反向引用:这些是%N形式的反向引用(0 <= N <= 9)。 %1到%9提供对模式的分组部分(再次用括号括起来)的访问,来自最后匹配的RewriteCond在当前条件集中。 %0提供对该模式匹配的整个字符串的访问。

因此,如果要同时捕获域和URL路径组成部分,则必须将RewriteCond DirectiveHTTP_HOST合并在一个REQUEST_URI

RewriteCond

0
投票

我有地址:product / name-name-500ml-12345我想获得name-name-500ml.html我有

RewriteCond%{REQUEST_URI} ^ / product /(。?)-(\ d +)RewriteRule。/%1.html [R = 301,L]

而且我只得到nam-name.html

如何更改我的RwrtieCound?

© www.soinside.com 2019 - 2024. All rights reserved.