Apache的htaccess的重写URL的搜索引擎优化友好 [英] apache htaccess rewrite url for seo friendliness

查看:260
本文介绍了Apache的htaccess的重写URL的搜索引擎优化友好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试和失败的那一刻重写我的网址,搜索引擎优化友好。你能指出我的可能是走错了?

我想改写这个网址:

<$p$p><$c$c>http://www.chillisource.co.uk/product?&cat=Grocery&q=Daves%20Gourmet&page=1&prod=B0000DID5R&prodName=Daves_Insanity_Sauce

要这样:

<$p$p><$c$c>http://www.chillisource.co.uk/product/Grocery/Daves%20Gourmet/1/B0000DID5R/Daves_Insanity_Sauce

这是我的.htaccess

  RewriteEngine叙述上
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_FILENAME} \ PHP -f
重写规则^(。*)$ $ 1.PHP

重写规则^产物/([一 - 杂 -  Z0-9] +)/([一 - 杂 -  Z0-9] +)/([一 - 杂 -  Z0-9] +)/([一 - 杂 -  Z0 -9] +)/([A-ZA-Z0-9] +)/产品及放大器;?2 Q = $&功放; 1猫= $&放页= $ 3及督促= $ 4和PRODNAME = $ 5
 

第一部分让我去没有在filenane中的.php。

这目​​前给我错误500当我尝试去:<一href="http://www.chillisource.co.uk/product/Grocery/Daves%20Gourmet/1/B0000DID5R/Daves_Insanity_Sauce" rel="nofollow">http://www.chillisource.co.uk/product/Grocery/Daves%20Gourmet/1/B0000DID5R/Daves_Insanity_Sauce

我已经读了mod_rewrite的,但我是一个新手程序员,发现它惨淡经营。我不明白怎么$ 1,$ 2,$ 3,$ 4,$ 5,它是我的网址中的变量得到转移到另一边,是([A-ZA-Z0-9] +)是否正确?

在此先感谢。

解决方案

$ 1对应的第一组括号中的重写规则的第一部分。 $ 2指第二组括号等。

戴夫斯%20Gourmet 包含空格字符,这是不是在你的第二个模式即第二组括号之间的事情占据了。同样,你不照顾的_ 在URL中。

我会尝试这种

 重写规则^产品/([A-ZA-Z] +)/([\ SA-ZA-Z0-9] +)/([0-9] +)/ ([A-Z0-9] +)/([A-ZA-Z _] +)/产品及放大器;猫= $ 1安培; Q = $ 2及页= $ 3及督促= $ 4和PRODNAME = $ 5
 

假设你的页面参数总是一个整数,你的第4个参数中只包含大写字母。

I am trying and failing at the moment to rewrite my urls for seo friendliness. Can you point out where I might be going wrong?

I'm trying to rewrite this url:

http://www.chillisource.co.uk/product?&cat=Grocery&q=Daves%20Gourmet&page=1&prod=B0000DID5R&prodName=Daves_Insanity_Sauce

To this:

http://www.chillisource.co.uk/product/Grocery/Daves%20Gourmet/1/B0000DID5R/Daves_Insanity_Sauce

This is my .htaccess

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

RewriteRule ^product/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+) /product?&cat=$1&q=$2&page=$3&prod=$4&prodName=$5

The first part allows me to go without the .php in the filenane.

This currently gives me error 500 when I try and go to: http://www.chillisource.co.uk/product/Grocery/Daves%20Gourmet/1/B0000DID5R/Daves_Insanity_Sauce

I've read up on mod_rewrite but I'm a novice programmer and finding it hard going. I don't get how $1, $2, $3, $4, $5 which are the variables in my url get transfered to the other side, is ([a-zA-Z0-9]+) correct?

Thanks in advance.

解决方案

$1 corresponds to your first set of parenthesis in the first part of your rewrite rule. $2 to the second set of parenthesis and so on.

Daves%20Gourmet contains a space character which is not accounted for in your 2nd pattern i.e. things between 2nd set of parenthesis. Again you are not taking care of _ in the url.

I would try this

RewriteRule ^product/([a-zA-Z]+)/([\sa-zA-Z0-9]+)/([0-9]+)/([A-Z0-9]+)/([a-zA-Z_]+) /product?&cat=$1&q=$2&page=$3&prod=$4&prodName=$5

Assuming your page parameter is always an integer and your 4th parameter contains only upper case letters.

这篇关于Apache的htaccess的重写URL的搜索引擎优化友好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆