RewriteEngine on
RewriteRule ^([^/.]+)/?$ category.php?slug=$1
RewriteRule ^([^/.]+)/([^/.]+)$ product-details.php?slug1=$1&slug=$2
RewriteRule ^([^/.]+)/?$ infrastructure-details.php?slug=$1
what I have already tried
This is my htaccess file. problem is when I am trying to execute (infrastructure-details.php?slug=$1
) its move to (category.php?slug=$1
) conflict with first rule of htaccess.
I tired multiple rewrite methods but its not working. Please help to solve this issue.
2
Answers
This is work fine for me. (infrastructure-details.php?slug=$1 [L]) put on top.
There is no discernible pattern that differentiates these two URLs so the only way to implement these two rewrites is to hardcode them. For example:
Where the
$0
backreference in the substitution string contains the entire match by theRewriteRule
pattern (just saves some repetition).If you need a more general solution (as your directives suggest) then there needs to be a discernible pattern in the URL that differentiates URLs that should be rewritten to
category.php
andinfrastructure-details.php
respectively.I’m assuming your
.htaccess
file, and other files, are is inside the/project
subdirectory.Rule #1 and #3 conflict – they use exactly the same pattern (regex) to match against the requested URL. The first rule is always going to "win" and rewrite the request before rule#3 is able to process the request, so rule#3 never matches.
To write a generic rule like this there needs to be a discernible difference between the URL types that you can match with a pattern/regex. For example:
And then you can construct rules…
Note that the order of these directives can be important. More specific rules need to be before more generalised rules.