Y
Y
Yapryntsew2016-01-08 14:47:21
PHP
Yapryntsew, 2016-01-08 14:47:21

How to specify mod_rewrite exceptions?

Links like site.ru/index.php?type=value will be converted to site.ru/value. Is it possible to make exceptions for some value and use a different rule for them?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Nalomenko, 2016-01-08
@Yapryntsew

If I understand the task correctly, then you will not convert the first into the second, but just the opposite - you will convert the context / value into passing the GET parameter type with the value value to the index.php script
For individual values ​​(in this case) you can write: So:

RewriteEngine On

RewriteRule ^contacts$ contacts.php [L]
RewriteRule ^about$ about.php [L]
RewriteRule ^([a-zA-Z0-9_/-]+)$ index.php?type=$1 [L]

That is, everything that is passed after the first slash and falls under the [a-zA-Z0-9_/-]+ mask will be passed as type to index.php , except for the contacts and about values ​​- they will be redirected to other scripts.
Note: It is very important to respect the order of the rules, as the first RewriteRule that matches the requested URL is executed. Considering that both contacts and about fall under the [a-zA-Z0-9_/-]+ mask , if their handlers were specified below, would the rule redirecting them to index.php?type=contacts and index.php? type=about

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question