我怎样才能实现这个目标
Existing URL :
newsDetails.php?cid=1&nid=$5698
所以我想重写为新网址:
news-1/details/1000
.htaccess文件的内容:
# For security reasons, Option all cannot be overridden.
#Options All -Indexes
RewriteEngine on
RewriteBase /
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^news-(\d+)/[^/]+/(\d+)/?$ newsDetails.php?cid=$1&nid=$2 [L,NC,QSA]
答案 0 :(得分:1)
您可以在DOCUMENT_ROOT/.htaccess
文件中使用此代码:
RewriteEngine On
RewriteBase /
RewriteRule ^news-(\d+)/[^/]+/(\d+)/?$ newsDetails.php?cid=$1&nid=$2 [L,NC,QSA]
答案 1 :(得分:0)
我更喜欢用PHP来实现它。你只需要重写像
....
RewriteRule ^(.*)$ /index.php/$1 [L]
如果您想使用现有的网址,请从旧文件中进行PHP重定向。