1

I have a rewrite rule but it is not working as expected.

Rewrite rule.

RewriteRule ^([^/]+)$ category.php?cat_alias=$1

In server side I get filename as value in request

Array
(
    [cat_alias] => category.php
)

Below is the example url for this rewrite rule http://www.example.com/news

Expected result :

Array
    (
        [cat_alias] => news
    )

1 Answer 1

1

Problem is that your rule doesn't have conditions and it is writing anything that is not / to category.php. After it rewrite /news rules are executed again in next loop and it performs another rewrite of /category.php.

You need to add rewrite condition to prevent existing files and directories to be rewritten and prevent looping.

# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)$ category.php?cat_alias=$1 [L,QSA]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.