Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

We have a website where the URL looks something like,

( "smart" being selector added on the app server based on the useragent if its a smart phone device)

We need to redirect the page to 404 if the URL is changed by the user as like below:


I tried with the below rule, but this redirects to 404 only for 1) and not for 2)

RewriteCond  %{REQUEST_URI} !^(.*)(-)\.html$
RewriteRule (.*)\.(.*).smart.html$ - [R=404,L] 

Any pointers on this would be of great help.

share|improve this question

migrated from Oct 10 '12 at 2:01

This question came from our site for professional and enthusiast programmers.

1 Answer 1


RewriteCond  %{REQUEST_URI} !^(.*)(-)\.html$
RewriteRule (.*)\.smart(\..*)?\.html$ - [R=404,L] 
share|improve this answer
watch out for those dots, \.(.*).smart will not match the in #2 – Tom McClure Oct 4 '12 at 23:31
Thanks Jon, but again now Behavior is reversed. #2 redirects to 404 but #1 doesn't. Any other suggestions? – user1720607 Oct 5 '12 at 5:52
@user1720607 The first URL redirects to a 404 when I put those rules in a blank htaccess file and request / – Jon Lin Oct 5 '12 at 17:48
Thanks Jon, yes it worked. I had to rearrange existing rules. – user1720607 Oct 9 '12 at 4:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.