I found several topics on mod_rewrite on stackoverflow but none them solved my problem. I also tried tutorial on this website http://edrackham.com/apache/beginners-mod_rewrite-tutorial/ I have been trying to use mod_rewrite to get clean url. For example:
www.myweb.com/itemdetail.php?itemid=111234
to
www.myweb.com/itemdetail/111234 or
www.myweb.com/itemdetail/iphone
This is my .htaccess file content.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %(REQUEST_FILENAME) !-l
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
As suggested in stackoverflow, I added following rewriterule to above file
RewriteRule ^itemdetail/([0-9]+)/$ itemdetail.php?itemid=$1 [NC,L]
But this did not solve my problem. Any suggestion is appreciated.
您应该将最后一个斜杠设为可选:
RewriteRule ^itemdetail/([0-9]+)/?$ itemdetail.php?itemid=$1 [NC,L]
On some servers you can't use a slash in a RewriteRule (I have the same problem). To check this try the following as your htaccess file:
RewriteEngine on
RewriteRule ^itemdetail-([0-9]+)/?$ itemdetail.php?itemid=$1
Of course your permalink would be www.myweb.com/itemdetail-111234 当然,您的永久链接将是www.myweb.com/itemdetail-111234
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.