I have following code in .htaccess
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)(/([^/]+))?(/(edit)+)(/([^/]+))?/?$ edit.php?secret=Y7qD7&category=$1&slug=$3&edit=$5&part=$7 [L]
RewriteRule ^([^/]+)(/([^/]+))?/?$ content.php?category=$1&slug=$3 [L]
RewriteRule ^(/)?$ content.php [L]
What I expect to achieve is
http://example.com/test/test1/edit/part to edit.php?category=test&slug=test1&edit=edit&part=part
http://example.com/test/edit/part to edit.php?category=test&slug=&edit=edit&part=part
(above rewrite is working as expected)
`http://example.com/test/test/` to `content.php?category=test&slug=test`
`http://example.com/test/` to `content.php?category=test&slug=`
(Please note that there is no “/edit/” & “/part/” in above 2 urls)
for above two rewrites, first one is working fine but the second one is not working as expected. The last one get rewrite to content.php?category=content.php&slug= which is not correct.
Also trailing slash should not make a difference for the rewrite.
Could somebody please show me what I’m doing wrong here?
I didn’t check why the rule in your question doesn’t work as expected, but you may try this instead:
Maps silently:
http://example.com/val1/up tohttp://example.com/val1/val2/val3/val4/with or without trailing slashesTo:
http://example.com/edit.php?key1=val1&key2=val2&key3=val3&key4=val4The maximum quantity of
valNvalues passed in the incoming URL, is 4. The minimum is 1. That range can be adjusted modifying the rule, though.When any
valNis not present in the incoming URL, the value in the corresponding key-value pair in the query added to the substitution URL, will be empty.However, the
keywill always be present in the query as allkeysare fixed strings not passed by the incoming URL.This rule-set is tested and working and it should be tested without any other rule that might get in conflict with it. I didn’t check the other rules in the question and can’t say if they work or if they could affect this one. That was not part of the question.
UPDATE
Redirecting to edit.php:
Mapping to edit.php is required only when there are 3 or 4 folders in the URL-path.
The modified rule-set is:
Maps silently:
http://example.com/val1/val2/val3/up tohttp://example.com/val1/val2/val3/val4/with or without trailing slashesTo:
http://example.com/edit.php?key1=val1&key2=val2&key3=val3&key4=val4The maximum quantity of valN values passed in the incoming URL, is 4. The minimum is 3.
Redirecting to content.php:
Mapping to content.php is very similar to the previous one, except is done only when the number of folders is 1 or 2.
So the rule-set is basically the same with less regex groups:
Maps silently:
http://example.com/val1/up tohttp://example.com/val1/val2/with or without trailing slashesTo:
http://example.com/content.php?key1=val1&key2=val2The maximum quantity of valN values passed in the incoming URL, is 2. The minimum is 1.
The complete rule-set is like this:
Hope I understood what you want.