apache htaccess 重写 url 以提高 seo 友好性
我正在尝试重写我的网址以提高搜索引擎优化友好性,但目前失败了。你能指出我哪里可能出错吗?
我正在尝试重写此网址:
http://www.chillisource.co.uk/product?&cat=Grocery&q=Daves%20Gourmet&page=1&prod=B0000DID5R&prodName=Daves_Insanity_Sauce
对此:
http://www.chillisource.co.uk/product/Grocery/Daves%20Gourmet/1/B0000DID5R/Daves_Insanity_Sauce
这是我的 .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
第一部分允许我在文件名中不包含 .php。
当我尝试访问时,当前会出现错误 500: 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]+) 正确吗?
提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
$1 对应于重写规则第一部分中的第一组括号。 $2 到第二组括号,依此类推。
Daves%20Gourmet
包含一个空格字符,该字符未在您的第二个模式中考虑,即第二组括号之间的内容。同样,您没有处理网址中的_
。我会尝试这个
假设您的页面参数始终是整数并且您的第四个参数仅包含大写字母。
$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
Assuming your page parameter is always an integer and your 4th parameter contains only upper case letters.