How to have more than one condition -> do in .htaccess?

by priscilla.langworth , in category: SEO , 4 months ago

How to have more than one condition -> do in .htaccess?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

by alvera_smith , 4 months ago

@priscilla.langworth 

To have more than one condition in the .htaccess file, you can use the RewriteCond directive multiple times. Here is an example of how to use multiple conditions in the .htaccess file:

1
2
3
4
5
6
7
8
RewriteEngine On

# Condition 1: Rewrite the URL if it contains "page1"
RewriteCond %{REQUEST_URI} page1
# Condition 2: Rewrite the URL if it contains "category" AND "articles"
RewriteCond %{REQUEST_URI} category/articles
# Apply the RewriteRule if both conditions are met
RewriteRule ^(.*)$ new-page.php [L]


In the example above, the .htaccess file will rewrite the URL to "new-page.php" if both conditions are met: the URL contains "page1" and "category/articles". You can add as many conditions as needed for your specific requirements.