简体   繁体   中英

.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) «$»

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM