文章当前可用的网址如下:
http://domain.com/index.php/news/{CATEGORY_ID}/{ARTICLE_ID}-{slug}.html
但我也需要这个 url 才能工作(通过 htaccess 301 重定向)
http://domain.com/index.php/news/article/view/{CATEGORY_ID}/{ARTICLE_ID}/
请帮助实现带参数的重定向。这是我的 .htaccess 文件的内容:
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !\.(ico|js|gif|jpeg|jpg|png|css|swf|flv)$ index.php
谢谢
答案1
这应该有效:
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/index\.php/news/article/view/(.+)/(.+)$
RewriteRule .* /index.php/news/%1/%2-all-the-same.html [L,R=301,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !\.(ico|js|gif|jpeg|jpg|png|css|swf|flv)$ index.php
答案2
RewriteRule index.php/news/article/view/(.*)/(.*) index.php/news/$1/$2
答案3
假设类别和文章ID都是数字:
RewriteRule /index\.php/news/article/view/(\d+)/(\d+)/$ /index.php/news/$1/$2.html
如果 ID 不是数字,则应将其替换为([^/]+)
。