How do I rewrite multiple URLs at once?

I have a series of price lists from different manufacturers (spat out from the database). They are limited to 100 lines per page, i.e.:

www.domain.com/products/price-lists/company1.php?page=2 www.domain.com/products/price-lists/company2.php?page=10 

which I want to rewrite to:

 www.domain.com/products/price-lists/company1/page/2 www.domain.com/products/price-lists/company2/page/10 

I have:

 Options +FollowSymlinks RewriteEngine On RewriteBase / RewriteRule ^products/price-lists/company1/page/([0-9]+)/?$ products/price-lists/company1.php?page=$1 [NC,L] RewriteRule ^products/price-lists/company2/page/([0-9]+)/?$ products/price-lists/company2.php?page=$1 [NC,L] 

First of all, this calls 404 if I try to go to / products / prices -lists / company1 / page / 2 (it works if I delete / page /), and secondly, I was wondering if I can combine them in any rule:

 (company1|company2[0-9]+)/? 

Thanks for any help (this is my first attempt at mod_rewrite!)

+4
source share
2 answers

Try the following:

 Options +FollowSymlinks RewriteEngine On RewriteBase / RewriteRule ^products/price-lists/([a-z0-9_\-]+)(/page)?/?$ products/price-lists/$1.php?page=1 [NC,L] RewriteRule ^products/price-lists/([a-z0-9_\-]+)/page/([0-9]+)/?$ products/price-lists/$1.php?page=$2 [NC,L] 

The first rule will check the presence or absence of a page without a number and go to page 1. ([a-z0-9_\-]+) will be used to place the company, so if you put:

 http://www.domain.com/products/price-lists/stackoverflow/page/2 

/products/price-lists/stackoverflow.php will open with $_GET['page'] = 2

+4
source

The problem is that part of the URL is the same as the php file name (without .php ). Use the following to fix it.

options -multiviews

+1
source

Source: https://habr.com/ru/post/1387945/


All Articles