Reputation: 45
I'm trying to match a url using regex in a .htaccess file.
I am able to match the end of the string using "$" just fine, but when I try to match the start of the string using "^", the RewriteRule stops working.
Here is my .htaccess file:
RewriteEngine On
RewriteBase "/"
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule "^example-url$" "index.php"
Without the "^" the regex will work, but is too lax. I've fiddled with this for a couple of hours now, but I'm not sure what else to try, since this very basic regex, that has worked in every regex tester I've tried.
My best guess atm is that it has something to do with what the start of the string actually is, but I'm not sure how to test this, since it should start just after the top level domain name with the "/".
EDIT: Moving the .htaccess to the html folder made all my problems go away, the above .htaccess file now works fine. Thanks so much for the help @Riad Loukili and @P0lT10n.
I'm guessing my problems were caused by the way my virtual directories are setup.
Upvotes: 3
Views: 722
Reputation: 119
Not sure but try
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^example-url$ index.php
I tried it on This .htaccess tester and it worked.
Possible Explanation: You've already specified the RewriteBase, no need to start the url with / in the Regular Expression.
Upvotes: 3