[英]How to make correct mod_rewrite rules in.htaccess
I am trying to make rewrite rule which rewrite this long url to a SEO friendly one. 我试图制定重写规则,将这个长网址重写为SEO友好的网址。 However, my rule didn't work and the destination url become a 404 page.
但是,我的规则不起作用,目标网址变成了404页。 I would appreciate any helps.
我将不胜感激。 Thank you!
谢谢!
This is an example of original URL 这是原始网址的示例
http://www.mydomain.com/index.php?module=product&pId=102&id=14495&category=computer/DELL&start=0/ http://www.mydomain.com/index.php?module=product&pId=102&id=14495&category=computer/DELL&start=0/
This is my rewrite rule 这是我的改写规则
RewriteRule ^module/([^/] )/pId/([^/] )/id/([^/] )/category/([^/] )/start/([^/]*)$ /index.php?module=$1&pId=$2&id=$3&category=$4&start=$5 [L] RewriteRule ^ module /([[^ /] )/ pId /([^ /] )/ id /([^ /] )/ category /([^ /] )/ start /([^ /] *)$ / index .php?module = $ 1&pId = $ 2&id = $ 3&category = $ 4&start = $ 5 [L]
This is transformed URL 这是转换后的网址
http://www.mydomain.com/index/module/product/pId/102/id/14495/category/computer/DELL/start/0/ http://www.mydomain.com/index/module/product/pId/102/id/14495/category/computer/DELL/start/0/
Just from a quick glance, you are matching for /start/[^/]*$
. 乍一看,您就可以匹配
/start/[^/]*$
。 But your URL contains a trailing forward slash start/0/
, which your regex excludes. 但是您的URL包含一个正斜杠
start/0/
,正则表达式不包含此前缀。
So it might be best to either allow a spare slash with /?
因此,最好在
/?
后面加上一个斜杠/?
or rather make the last match pattern completely imperceptive with /start/(.*)$
allowing everything. 或者更确切地说,通过
/start/(.*)$
允许最后的匹配模式完全不被察觉。
But anyway, just removing file extensions and trading ampersands and equal signs for forward slashes doesn't make for nicer or user-friendly URLs. 但是无论如何,仅仅删除文件扩展名和交易“&”号和正斜杠的等号并不能使URL更好或更友好。 The goal should be parameter consolidation for readability.
目标应该是参数合并以提高可读性。 Contemporary search engines don't care about GET parameters really.
当代的搜索引擎实际上并不在乎GET参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.