在基于smarty的网站中重写URL?
我想做到这一点在基于smarty的网站中重写URL?,url,.htaccess,mod-rewrite,Url,.htaccess,Mod Rewrite,我想做到这一点 example.com/search_results/?action=search&username[equal]=PorscheSA 到 我已经为许多网站使用了.htaccess来实现这一点,但由于这个网站是基于smarty的,它似乎不起作用。任何帮助都将不胜感激 好的,这是.htaccess文件: RewriteCond %{HTTP_HOST} ^www.example.com [NC] RewriteRule ^(.*)$ http://example.com/
example.com/search_results/?action=search&username[equal]=PorscheSA
到
我已经为许多网站使用了.htaccess来实现这一点,但由于这个网站是基于smarty的,它似乎不起作用。任何帮助都将不胜感激
好的,这是.htaccess文件:
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* ./index.php
为了实现以下目标,我尝试了以下方法:
RewriteRule ^([a-zA-Z0-9-_+^/])/$ /search_results/?action=search&username[equal]=$1
但是什么也没发生。你的问题仍然有点模糊,你到底希望发生什么,但是既然你已经发布了你的
.htaccess
,我会试试看,看看我是否明白你的意思
RewriteRule
不起作用的最明显原因是您的测试模式与您作为示例提供的URL不匹配,因为您的RewriteRule
需要一个尾随斜杠(并且只匹配前面的一个字符)。此外,如果将它放在.htaccess
文件中当前的规则之后,它将永远不会匹配,因为请求将被重写为index.php
我想你想要这样的东西
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} =www.example.com [NC]
RewriteRule ^.*$ http://example.com/$0 [L,R=301]
# Make sure we end and force the redirect so %{REQUEST_FILENAME} gets changed
RewriteRule ^[a-zA-Z0-9-_+^/]+$ search_results/?action=search&username[equal]=$0 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php
但是,如果search\u results/
目录不存在,那么这将被重写为index.php
,因此我不确定在这种情况下重定向的目的是什么。而且,如果它确实存在,因为您的测试模式与我期望在站点路径中看到的几乎任何内容都匹配,那么所有内容都将被重写到search\u results/
目录,因此很少(如果有的话)会出现在站点根目录的index.php
基于此,我觉得您可能遗漏了其他一些标准,但我可能错了。基于smarty的网站与htaccess/RewriteRules不起作用无关。您必须更全面地描述您的设置以及您想要实现的目标。
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} =www.example.com [NC]
RewriteRule ^.*$ http://example.com/$0 [L,R=301]
# Make sure we end and force the redirect so %{REQUEST_FILENAME} gets changed
RewriteRule ^[a-zA-Z0-9-_+^/]+$ search_results/?action=search&username[equal]=$0 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php