1

I have the following url-rewriting in htaccess:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^category/([0-9]+)/([0-9a-zA-Z]+)/?([0-9a-zA-Zßäöü\s]+)?/?([0-9a-zA-Z.ßäöü\s]+)?/?([0-9a-zA-Z.ßäöü\s]+)?/?([0-9]+)? category.php?mid=$1&cid=$2&ccid=$3&cccid=$4&ccccid=$5&page=$6 [NC,L]

category/$1/$2 should open catagory.php?mid=$1&cid=$2 (and will start with page=1); this works fine with the above code.

However, I would like the following url's to work as well" category/$1/$2/$6 should open category.php?mid=$1&cid=$2&page=$6.

Please note $6 is always a number, the categories $2, $3, $4 and $5 are a combination of numbers and letters.

Examples:

  • category/19/sport (mid=19, cid=sport)

  • category/19/sport/2 (mid=19, cid=sport, page=2)

  • category/19/sport/soccer/2.championsleague/2016results (mid=19, cid=sport, ccid=soccer, cccid=2.championsleague, ccccid=2016results)

  • category/19/sport/soccer/2.championsleague/2016results/10 (mid=19, cid=sport, ccid=soccer, cccid=2.championsleague, ccccid=2016results, page=10)

How should I alter the URL rewrite?

3
  • @ anubhave, some examples added. Commented Apr 19, 2018 at 9:36
  • How come cccid parameter showing different values for same URL? Commented Apr 19, 2018 at 15:03
  • my fault, that should have been ccccid. I have corrected it above. Commented Apr 23, 2018 at 15:56

1 Answer 1

1

You may use these rule in your site root .htaccess:

Options -MultiViews
RewriteEngine On

# skip all rules below for real files and directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^category(\d+)/([^/]+)/?$ category.php?mid=$1&cid=$2 [L,NC,QSA]

RewriteRule ^category(\d+)/([^/]+)/(\d+)/?$ category.php?mid=$1&cid=$2&page=$3 [L,NC,QSA]

RewriteRule ^category(\d+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ category.php?mid=$1&cid=$2&ccid=$3&ccccid=$4&cccccid=$5 [L,NC,QSA]

RewriteRule ^category(\d+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/(\d+)/?$ category.php?mid=$1&cid=$2&ccid=$3&ccccid=$4&cccccid=$5&page=$6 [L,NC,QSA]
Sign up to request clarification or add additional context in comments.

2 Comments

@ Anubhave, is there a possibility that I leave the ^category out, so my URL looks like 19/sport/soccer/2.championsleague/2016results (mid=19, cid=sport, ccid=soccer, cccid=2.championsleague, ccccid=2016results) instead of category/19/sport/soccer/2.championsleague/2016results (mid=19, cid=sport, ccid=soccer, cccid=2.championsleague, ccccid=2016results)
Ye just remove category/ from all rules above. I am on mobile so unable to make edits.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.