whats wrong with this reg expression

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

whats wrong with this reg expression

Post by gurjit »

whats wrong with this reg expression, it does nothing

i am putting this in a .htaccess file and uploading it to the root directory. I want any link pointing to /estate-agents/<any file name>.html to redirect to /search/index.php?type=estate-agents


heres my mod rewrite condition

Code: Select all

 
RewriteEngine on
RewriteRule ^/estate-agents/(.*?).html$ /search/index.php?type=$1
 
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: whats wrong with this reg expression

Post by Apollo »

try ^estate-agents/(.+)\.html$

That is: without the / at the beginning, (.+) instead of (.*?) and a backslash before .html (to treat the . literally)
Or (.*) if you also want to allow an empty filename (i.e. "estate-agents/.html")

Not 100% sure if the beginning / should be excluded for all webservers, you could also do ^/?estate-etc.. to be sure. That way it works either with and without.
Post Reply