.htaccess rewrite all characters
Solution 1
(.*) will match all characters. That's all you need.
Solution 2
To match everything you can just use: ^(.+)/(.+)/?$
(with optional trailing slash)
If you want to stick with the existing format using character classes, you have a couple of problems here. Inside character sets/classes, you should always put hyphens at the end for a valid regex. You've also omitted uppercase characters. So to match a basic alphanumeric, underscore and hyphen you want:
[a-zA-Z0-9_-]
or, using character escapes:
[\w\d_-]
Your second bracket set is currently specifically excluding period and slash, matching all others.
If your application data is well-defined you may want to go with defined character classes, and 404 on all other data. If you want the blanket redirect, then the following should fix you up:
RewriteRule ^(.+)/(.+)/?$ index.php?engine=$1&q=$2 [NC,L]
armand
Updated on July 05, 2022Comments
-
armand almost 2 years
What pattern do I need to rewrite all characters in the requested URL? I tried:
RewriteRule ^([a-z\-_0-9]+)/([^/.]+)$ index.php?engine=$1&q=$2 [NC,L]
But the dots
.
are not getting recognized. -
armand over 13 yearsbut im getting some troubles with the images on the site, they are not appearing if I put the ruke like: ^([a-z\-_0-9]+)/(.*)$ index.php?engine=$1&q=$2any clue?
-
armand over 13 yearsit is working (both answers (*) and yours @tomwalsham but why are the images disappearing? as the path where not ok or re-chaged, any clues?
-
tomwalsham over 13 yearsYou will want to use the <base href='example.org'> tag to reset all relative references on the site to base, as with mod_rewrite they are interpreted as being executed in subfolders.
-
armand over 13 yearsmmm is not working, are u sure it is a problem of the php file and not of the .htaccess?
-
tomwalsham over 13 yearsIf the page is loading fine, but the images are broken, this is either a problem of the relative paths of the images being broken by the mod_rewrite, or that you're also rewriting the image paths to go to the index.php In Firefox you can RightClick->View Image to see if you're loading your main file. Alternatively, you will need to use a less broad regex, or a rewritecond.
-
tomwalsham over 13 years
RewriteCond %{REQUEST_URI} !^/images/
before the RewriteRule line may help you (assuming your images are all contained within /images/ -
armand over 13 yearsaww nothing! how could I add the dots on the last section ([^/.]+) for my rule ^([a-z\-_0-9]+)/([^/.]+)$ index.php?engine=$1&q=$2 if I take out the /. I have the same problem with the src's