开发者

.htaccess modrewrite problem

I have a website on wordpress and I have written a plugin which required SEO friendly URL now i am stuck at the following

http://domain.com/catalogue-category/1/ is working fine but when i replace the /1/ with the name of the category like http://domain.com/catalogue-category/Seating/ it does not work at all and gives me 404 error.

Its also working at /catalogue-category/?cat=Seating

My apache rewrite rule is

RewriteRule ^catalogue-category/^([^/]+)/$ /catalogue-category/?cat=$1 [L]

I am not that good in mod rewrite as that in PHP, so please bear my ignorance and treat me as a rookie.

Looking forward to hear 开发者_开发技巧from the gurus :)


Try:

RewriteRule ^catalogue-category/([^/]+)/$ /catalogue-category/?cat=$1 [L]

You were using the caret ^ twice in your regex pattern (^catalogue-category/^([^/]+)/$), the caret asserts that the match should be from the start of the string.

Pattern explanations

Previous pattern:

  1. Assert position at the beginning of the string «^»
  2. Match the characters “catalogue-category/” literally «catalogue-category/»
  3. Assert position at the beginning of the string «^»
  4. Match the regular expression below and capture its match into backreference number 1 «([^/]+)»
    1. Match any character that is NOT a “/” «[^/]+»
      1. Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
  5. Match the character “/” literally «/»
  6. Assert position at the end of the string (or before the line break at the end of the string, if any) «$»

Suggested one

  1. Assert position at the beginning of the string «^»
  2. Match the characters “catalogue-category/” literally «catalogue-category/»
  3. Match the regular expression below and capture its match into backreference number 1 «([^/]+)»
    1. Match any character that is NOT a “/” «[^/]+»
      1. Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
  4. Match the character “/” literally «/»
  5. Assert position at the end of the string (or before the line break at the end of the string, if any) «$»
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜