1
votes

I inserted this rule in my .htaccess file:

RewriteRule ^([A-Za-z0-9-]+)/?$   index.php?content=category&categoryname=$1  [NC,L]

In this way I can get friendly urls like this: http://localhost/mysite/london

I'd also like to use a friendly url for my contact page like so: https://localhost/mysite/index.php?content=message to become: https://localhost/mysite/contact

But if I insert the below rule into .htaccess...

RewriteRule   ^contact/?$   index.php?content=message  [NC,L] 

...it doesn't work as it seems that the rule for the categories affects this rule.

In fact, if I comment out the category rule...

#RewriteRule   ^([A-Za-z0-9-]+)/?$   index.php?content=category&categoryname=$1  [NC,L]

...the url friendly rule for the contact page works (https://localhost/mysite/contact)

So I'm looking for the possibility to exclude some parameter from the category rule to allow for a redirect in some case to another url.

Thanks for any suggestions...

1

1 Answers

0
votes

Firstly you need to make sure the contact rule is placed before the more generic one so htaccess can process it first:

RewriteRule ^contact/?$ index.php?content=message [NC,L]
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?content=category&categoryname=$1 [NC,L]

If you have it the other way around the generic rule will always be looked at and match before htaccess even gets to the contact rule.

Note though that the way you wrote your rules it will only match URLs such as

https://exmaple.com/contact

but not

https://exmaple.com/contact/something-else

However, looking at your more generic rule I assume this is intentional.