I am trying to create a rewrite rule which will detect numbers only and forward them accordingly. I want the rewrite rule to be ignored if anything but numbers appears.
/index.php
- OK/
- OK/42365
- rewrites to view.php?id=42365
What I have so far:
RewriteEngine on
RewriteRule ^([0-9]+)?$ view.php?id=$1 [L]
htaccess rewrite rule includes setting a combination of rewrite condition ( RewriteCond ) tests along with a corresponding rule ( RewriteRule ) if the prior conditions pass. In most cases, these rules should be placed at any point after the RewriteEngine on line in the . htaccess file located in the website's docroot.
htaccess rewrite rules can be used to direct requests for one subdirectory to a different location, such as an alternative subdirectory or even the domain root. In this example, requests to http://mydomain.com/folder1/ will be automatically redirected to http://mydomain.com/folder2/.
The $1 is basically the captured contents of everything from the start and the end of the string. In other words, $1 = (. *) .
Remove the ?
from the end of the ([0-9]+)
group, which makes it optional. You must have numbers for the rewrite to occur:
RewriteEngine on
RewriteRule ^([0-9]+)$ view.php?id=$1 [L]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With