Nick Roper
Nick Roper

Reputation: 137

Apache rewrite /product/ to /products/ and index.php

I've been asked to help on an ExpressionEngine site that's been developed. There is an existing .htaccess file that rewrites anything that isn't a file or directory so that it goes via index.php:

RewriteEngine On
RewriteBase /
# Not a file or directory (also catches index.php)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?$1 [L]

This works fine, and an example URL might be:

www.mysite.com/products/foo (plural 'products')

However, It also needs to deal with old URLs which will be in the form:

www.mysite.com/product/foo (singular 'product')

I've tried the following:

RewriteEngine On
RewriteBase /
# Not a file or directory (also catches index.php)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^product/(.+) /index.php/products/$1 [L]
RewriteRule ^(.*)$ /index.php?$1 [L]

Hoping that if it finds 'product' then it rewrites to 'products' via index.php and then quits, but it's not working.

At the same time, I need any incoming URL that starts:

/department/foo to be rewritten to:

/departments/category/foo

Any help greatefully received.

Upvotes: 0

Views: 459

Answers (1)

anubhava
anubhava

Reputation: 785186

You can use add a rule above your existing rule to for mapping product -> products:

RewriteEngine On
RewriteBase /

RewriteRule ^product(/.*)?$ products$1 [L,NC]

# Not a file or directory (also catches index.php)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?$1 [L]

Upvotes: 1

Related Questions