简体   繁体   English

.htaccess网址重写-删除.php-添加结尾斜杠-并缩短查询字符串

[英].htaccess url rewrite - remove .php - add trailing slash - and shorten query strings

I've been working on a CMS recently, and wanted to remove the .php add a trailing slash and remove query strings eg page.php?page=contact to page/contact 我最近一直在使用CMS,想删除.php并添加斜杠并删除查询字符串,例如page.php?page = contact到page / contact

So far my .htaccess file looks like this: 到目前为止,我的.htaccess文件如下所示:

# This is a .htaccess file
# Don't edit it.

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php\?page=([^&\s]+)&?
RewriteRule (.*)\.php$ /$1/%1/? [L,R=301]

RewriteRule ^([^/]+)/([^/]+)/$ $1.php?page=$2 [QSA,L]

other then that, I can't figure out how to shorten the query string. 除此之外,我不知道如何缩短查询字符串。 I've looked around on and couldn't find any other questions specific to this... 我环顾四周,找不到其他与此相关的问题...

Thank you in advance. 先感谢您。

I misunderstood you. 我误会了你 I though you just needed to truncate the query string. 我虽然您只需要截断查询字符串。 This would pull the page parameter value from the query string and append it to the URL. 这将从查询字符串中提取page参数值,并将其附加到URL。 ? truncates query string as before. 像以前一样截断查询字符串。

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php\?page=([^&\s]+)&?
RewriteRule (.*)\.php$ /$1/%1/? [L,R=301]

RewriteRule ^([^/]+)/([^/]+)/$ $1.php?page=$2 [QSA,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM