1

I have the following URL:

www.example.com/category/news/article-name

I need to drop the category/news and redirect to:

www.example.com/article-name

I have the following RewriteRule working:

RewriteRule ^category/news/(.*)$ https://example.com/$1 [R=301,L]

However, I need to edit the RewriteRule above to allow for the URL below to be loaded without redirecting:

www.example.com/category/news/

Currently this URL redirects to www.example.com

Is this possible?

2 Answers 2

1

Just change .* (0 or ore characters) to .+ (1 or more characters) in your rule:

RewriteRule ^category/news/(.+)$ /$1 [R=301,L,NC,NE]

Now it won't affect /category/news/ URL.

Remember to clear your browser cache while testing this change.

Sign up to request clarification or add additional context in comments.

Comments

0

Try Rewriting instead of redirecting, in this case you can call www.example.com/article-name which internally rewrite to www.example.com/category/news/article-name

please check.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond ^([\w-]+)$ category/news/$1 [L]

1 Comment

Thanks for your answer but this didn't work. I got an internal server error. However, this did work: RewriteRule ^category/news/(.+)$ /$1 [R=301,L,NC,NE]

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.