用 htaccess 重写搜索页面查询 URL
Rewrite search page query URL with htaccess
我希望提交搜索表单时,URL 是这样的:
localhost/xampp/external/proj3/search/searchquery
而不是这个:
localhost/xampp/external/proj3/tools/search/search.php?query=searchquery
您可以在 DOCUMENT_ROOT/.htaccess
文件中使用此代码:
RewriteEngine On
RewriteBase /xampp/external/proj3
# external redirect from action URL to pretty one
RewriteCond %{THE_REQUEST} /search(?:\.php)?\?query=([^\s&]+) [NC]
RewriteRule ^ search/%1? [R=302,L,NE]
# internal forward from pretty URL to actual URL
RewriteRule ^search/([^/.]+)/?$ search.php?query= [L,QSA,NC]
在您的文档根目录中创建一个 .htaccess
文件。并把这个:
RewriteEngine On
RewriteRule ^search/([a-zA-Z0-9]+)/?$ \
search.php?query= \
[NC,L]
注意:注意正则表达式。谨慎过滤。
我希望提交搜索表单时,URL 是这样的:
localhost/xampp/external/proj3/search/searchquery
而不是这个:
localhost/xampp/external/proj3/tools/search/search.php?query=searchquery
您可以在 DOCUMENT_ROOT/.htaccess
文件中使用此代码:
RewriteEngine On
RewriteBase /xampp/external/proj3
# external redirect from action URL to pretty one
RewriteCond %{THE_REQUEST} /search(?:\.php)?\?query=([^\s&]+) [NC]
RewriteRule ^ search/%1? [R=302,L,NE]
# internal forward from pretty URL to actual URL
RewriteRule ^search/([^/.]+)/?$ search.php?query= [L,QSA,NC]
在您的文档根目录中创建一个 .htaccess
文件。并把这个:
RewriteEngine On
RewriteRule ^search/([a-zA-Z0-9]+)/?$ \
search.php?query= \
[NC,L]
注意:注意正则表达式。谨慎过滤。