配置用于URL重写的htaccess [英] Configuring htaccess for url rewriting
本文介绍了配置用于URL重写的htaccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在努力重写此URL
http://localhost/sitecms/?search=viewPage&pageId=1
至
http://localhost/sitecms/pages/page/1
在index.php内部顶部声明的N.B.变量‘Search’,在index.php内声明为函数的viewPage接收pageID变量,并将其与关联数据一起传递给另一个文件夹(模板)内的viewPage.php。
下面是我的.htaccess
代码。
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^pages/([^/]+)/?$ ?search=viewPage&pageId=$1 [L]
它不起作用。
非常欢迎对我错过的内容提出建议。
推荐答案
结合您展示的示例,您可以尝试以下操作吗? 请在测试URL之前清除浏览器缓存。
Options +FollowSymLinks
Options -MultiViews
RewriteEngine ON
##This rule redirects from http://localhost/sitecms/?search=viewPage&pageId=1 TO http://localhost/sitecms/pages/page/1
RewriteCond %{THE_REQUEST} s/(sitecms)/?search=viewPage&pageId=(d+) [NC]
RewriteRule ^ /%1/pages/page/%2? [R=301,NE,L]
##Rules for handling non-existing files/directories.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(sitecms)/(?:[^/]*)/(?:[^/]*)/(d+)/?$ $1/?search=viewPage&PageId=$2 [NC,L]
这篇关于配置用于URL重写的htaccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文