[英]Dynamic URL rewrite help using .htaccess
我该如何实现
Existing URL :
newsDetails.php?cid=1&nid=$5698
所以我想重写为新的URL:
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]
您可以在DOCUMENT_ROOT/.htaccess
文件中使用以下代码:
RewriteEngine On
RewriteBase /
RewriteRule ^news-(\d+)/[^/]+/(\d+)/?$ newsDetails.php?cid=$1&nid=$2 [L,NC,QSA]
我更喜欢在PHP中完全实现它。 你只需要这样的重写
....
RewriteRule ^(.*)$ /index.php/$1 [L]
如果您想使用现有的URL,请从旧文件进行PHP重定向。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.