Reputation: 1074
So, I'm trying to have a RegEx at my .htaccess that uses RewriteRule to redirect website.
My idea is to redirect all URLs that are not files, and I used to do it like this:
RewriteRule ^([^\.]+)/?$ index.php?url=$1 [L]
Problem with this ^([^\.]+)/?$
RegEx is that URLs like following are not being rewrited when I want:
It worked really nice, but as soon as users started using dots (.) in their username, it obviously stopped working. I was assuming all URLs that have a dot (.) would be files, like these:
The solution I'm thinking about would be to add a set of words that I know that are URLs that must be rewritten, like if the contain words like as /username, /profile, /picture
So... how can I build a RegEx expression in a way that:
I was trying something like this:
[^\.]|([\S]+(\b\/(profile|username)\/)+[\S])?
But obviously does not work
Upvotes: 1
Views: 461
Reputation: 785551
Easier would be to use RewriteCond
like this to avoid rewriting any files and directories but let pattern match anything:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/?$ index.php?url=$1 [L,QSA]
Upvotes: 2