my boss wants me to code an URLrewriting for, let’s say “http://our.domain.com/SomeText” — that is, if the URL does NOT contain “.php” or “.html”, it should be processed by a script like “http://our.domain.com/process.php?string=SomeText“.
Is this possible with a simple regex? I just cannot find the right expression to do this.
I started by redirecting requests to some special subdir, but now it should work directly without any further subdir, so I somehow have to separate regular requests for exuisting pages to requests that don’t contain “.php” or “.html”…
Any advice or link for me?
Best regards,
Roman.
Using mod_rewite you could do this to re-write .php and .html URLs like this:
However you may also want to stop it from re-writing URLs to files which actually exist. (There may be other files lying around – images/css etc. which you don’t want to be re-written) You could amend the above to add checks:
Adding this check may mean that you don’t actually need check whether the extension is anything other than .php or .html, because you know that it will only be rewritten if the requested file does not exist, so you could amend the RewriteRule line to be this:
This will mean any requested URL that does not exist as a file will be handled by process.php.