动态URL重写帮助使用.htaccess

时间:2015-01-11 13:24:59

标签: php .htaccess url-rewriting

我怎样才能实现这个目标

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]

2 个答案:

答案 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重定向。