【发布时间】:2019-12-17 13:34:45
【问题描述】:
我有一个格式为
的 URLmotors.com/project?id=1&title=british-car-auctions
并希望将其更改为
motors.com/project/1/british-car-auctions
我使用了来自URL rewriting with PHP 和Rewritting URL by htaccess 的解决方案,但没有成功。至于 URL 的 title 部分,我用数据库中的破折号来调用这个确切的文本,这应该不是问题。这个问题有什么可能的解决方案吗?
# mode_rewrite starts here
RewriteEngine on
# does apply existing directories, meaning that if the foilder exists
RewriteCond %{REQUESTED_FILENAME} !-d
# check for file in directory with .hmtl extension
RewriteCond %{REQUEST_FILENAME}\.php -f
# here we actually show the page that has the .html extension
RewriteRule ^(.*)$ $1.php [NC,L]
#-----------------------------------------------------
RewriteCond %{REQUESTED_FILENAME} !-d
# check for file in directory with .hmtl extension
RewriteCond %{REQUEST_FILENAME}\.html -f
# here we actually show the page that has the .html extension
RewriteRule ^(.*)$ $1.html [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^news/([0-9]+)(/?)$/([0-9a-zA-Z\s_]+) news/article.php?id=$1&title=$2 [NC,L]
【问题讨论】:
标签: .htaccess mod-rewrite url-rewriting