new to mod_rewrite. I simply want to make something like this:
# Turn on the rewriting engine
RewriteEngine On
# use item php page to show the item
RewriteRule ^parts/./[.]$ parts/item.php?id=$1 [NC]
so when a person types in example.com/parts/anything/anything, the URL will go to
example.com/parts/item.php?id=the2ndanything
From my understanding, the period means any character. Also, I tried to add a + after the period(which should mean as much as anything), but that still didn't work.
by the way, I am on a temporary URL, since I have not changed my previous web host yet, and therefore my actual full URL has a ~ in it. I am hoping this is not an issue for mod_rewriting and therefore being the issue that stops it from working. the .htaccess file is in the root folder with the web sites index.html.
The .
does mean any character , but you must follow it by +
(one or more) or *
(zero or more) and you must capture it in ()
to be used as $1
. Use [^/]+
to match all characters up to but not including /
to match but not capture the first directory after parts/
.
RewriteEngine On
# (.*) captures the second "anything" in $1
RewriteRule ^parts/[^/]+/(.*)$ parts/item.php?id=$1 [L]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.