Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9237441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:32:09+00:00 2026-06-18T07:32:09+00:00

I have following code in .htaccess Options +FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-l RewriteCond

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T07:32:10+00:00Added an answer on June 18, 2026 at 7:32 am

    I didn’t check why the rule in your question doesn’t work as expected, but you may try this instead:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI}  ^/([^/]+)/?([^/]*)?/?([^/]*)?/?([^/]*)?/?
    RewriteRule .*    edit.php?key1=%1&key2=%2&key3=%3&key4=%4     [L]
    

    Maps silently:

    http://example.com/val1/ up to

    http://example.com/val1/val2/val3/val4/ with or without trailing slashes

    To:

    http://example.com/edit.php?key1=val1&key2=val2&key3=val3&key4=val4

    The maximum quantity of valN values passed in the incoming URL, is 4. The minimum is 1. That range can be adjusted modifying the rule, though.

    When any valN is 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 key will always be present in the query as all keys are 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:

    RewriteEngine On
    RewriteBase /
        
    RewriteCond %{REQUEST_URI} !edit\.php  [NC]
    RewriteCond %{REQUEST_URI}  ^/([^/]+)/([^/]+)/([^/]+)/?([^/]*)?/?$  [NC]
    RewriteRule .*    edit.php?key1=%1&key2=%2&key3=%3&key4=%4     [L,QSA]
    

    Maps silently:

    http://example.com/val1/val2/val3/ up to

    http://example.com/val1/val2/val3/val4/ with or without trailing slashes

    To:

    http://example.com/edit.php?key1=val1&key2=val2&key3=val3&key4=val4

    The 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:

    RewriteCond %{REQUEST_URI} !content\.php  [NC]
    RewriteCond %{REQUEST_URI}  ^/([^/]+)/?([^/]*)?/?$  [NC]
    RewriteRule .*    content.php?key1=%1&key2=%2   [L,QSA]
    

    Maps silently:

    http://example.com/val1/ up to

    http://example.com/val1/val2/ with or without trailing slashes

    To:

    http://example.com/content.php?key1=val1&key2=val2

    The maximum quantity of valN values passed in the incoming URL, is 2. The minimum is 1.

    The complete rule-set is like this:

    Options +FollowSymLinks 
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{REQUEST_URI} !edit\.php  [NC]
    RewriteCond %{REQUEST_URI}  ^/([^/]+)/([^/]+)/([^/]+)/?([^/]*)?/?$ [NC]
    RewriteRule .*    edit.php?key1=%1&key2=%2&key3=%3&key4=%4  [L,QSA]
    
    RewriteCond %{REQUEST_URI} !content\.php  [NC]
    RewriteCond %{REQUEST_URI}  ^/([^/]+)/?([^/]*)?/?$  [NC]
    RewriteRule .*    content.php?key1=%1&key2=%2   [L,QSA]
    

    Hope I understood what you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following .htaccess file Options +FollowSymLinks RewriteEngine on RewriteRule (.*)-pid-(.*)\.html$ product.php?n=$1&pid=$2 and
I have the following HTACCESS code: Options +FollowSymLinks RewriteEngine On RewriteBase / #RewriteCond %{REQUEST_URI}
I have the following code: RewriteEngine on #Options +FollowSymLinks RewriteCond %{HTTP_HOST} ^raal.co.il RewriteRule (.*)
I have follwing code in .htaccess file Options +FollowSymLinks RewriteEngine on RewriteRule tricks tricks.php?show=all
i have used the following code in .htaccess Options +FollowSymlinks RewriteEngine On RewriteBase /
i have the following .htaccess file for me web Options +FollowSymLinks RewriteEngine on RewriteRule
I have the following htaccess code: <IfModule mod_rewrite.c> RewriteEngine On RewriteCond !{HTTPS} off RewriteRule
I have the following code in my .htaccess file RewriteEngine on RewriteRule ^thumbnail/(.*).png thumbnail.php?url=$1
I have the following code in my .htaccess: RewriteEngine On RewriteBase / RewriteRule ^index\.php$
I have the following code: RewriteEngine On RewriteRule ^user/([0-9]+)/([0-9]+)/?$ template.php?user_id=$1&slide=$2 [NC,L,QSA] So when I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.