0

I have some problems with rewrite rule. I have 2 scripts, article.php?url= and product.php?ulrprodus= and I want to setup for them rewrite rules like below:

My Rewrite rules:

RewriteEngine On
Options +FollowSymLinks
RewriteRule ^([a-zA-Z0-9-/]+).html$ article.php?url=$1 
RewriteRule ^([a-zA-Z0-9-/]+).html$ produs.php?urlprodus=$1 

Only one rewrite is functioning article.php?url=$1. If I reverse the order also only rewrite will functioning but this time product.php?urlprodus=$1.

I need both to be functional.

  • 2
    The patterns on both rules are the same. How is Apache supposed to know which rule to use for any given url? – Flup Nov 11 '14 at 10:24
1

You need to have something like this

RewriteEngine On
Options +FollowSymLinks

RewriteRule ^article/([a-z0-9-/]+).html$ article.php?url=$1  [NC,L]
RewriteRule ^produs/([a-z0-9-/]+).html$ produs.php?urlprodus=$1 [NC,L]

So rewrite matches are different; now you would be able to make rewrite from say

www.domain.tld/article/myRewriteRule.html 

to

www.domain.tld/article.php?url=myRewriteRule

In action;

$ cat .htaccess 
RewriteEngine On
RewriteRule ^article/([a-zA-Z0-9-/]+).html$ article.php?url=$1  [NC,L]
RewriteRule ^produs/([a-zA-Z0-9-/]+).html$ produs.php?urlprodus=$1 [NC,L]

$ cat article.php 
<?
print_r($_GET);
?>

$ curl -i localhost/article/hello-world.html
HTTP/1.1 200 OK
Date: Tue, 11 Nov 2014 12:57:38 GMT
Vary: Accept-Encoding
Content-Length: 35
Content-Type: text/html

Array
(
    [url] => hello-world
)
  • Hi sir,i tried your method and it doesn't work. url is like categorie-1/subcategorie-1.html and urlprodus is like categorie-1/subcategorie-1/produs-subcategorie-1.html .Both of them I extract from the MySQL database. – constantin Nov 11 '14 at 12:24
  • I've updated answer with details and checks I made – Hrvoje Špoljar Nov 11 '14 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.