在php中,如何从URL中删除查询字符串以及访问页面的文件名?
我有一个网址https://testing.in/show_tmp?tmp=abcval. 我想要一个干净的网址像https://testing.in/abcval 不破坏网站的功能。我的网站是建立在核心PHP。我知道我们可以使用htacess文件实现这一点,但我不知道如何实现,请帮助我 htaccess文件代码在php中,如何从URL中删除查询字符串以及访问页面的文件名?,php,.htaccess,Php,.htaccess,我有一个网址https://testing.in/show_tmp?tmp=abcval. 我想要一个干净的网址像https://testing.in/abcval 不破坏网站的功能。我的网站是建立在核心PHP。我知道我们可以使用htacess文件实现这一点,但我不知道如何实现,请帮助我 htaccess文件代码 # DO NOT REMOVE THIS LINE AND THE LINES BELOW SSL_REDIRECT:connectwithme.in RewriteEngine on
# DO NOT REMOVE THIS LINE AND THE LINES BELOW SSL_REDIRECT:connectwithme.in
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^connectwithme.in$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# DO NOT REMOVE THIS LINE AND THE LINES ABOVE SSL_REDIRECT:connectwithme.in
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^.]+)$ $1.php [NC,L]
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/?show_tmp$ [NC]
RewriteRule /?(.+) show_tmp?tmp=$1 [NC,L,QSA]
我们添加了一个重写条件,因为当前请求URI不应该包含show_tmp,以避免太可能重定向的问题。稍后,我们只捕获请求URI并重定向到show_tmp 演示: 协助Anydesk访问后,您的最终.htaccess应如下所示:
# DO NOT REMOVE THIS LINE AND THE LINES BELOW SSL_REDIRECT:connectwithme.in
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^connectwithme.in$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# DO NOT REMOVE THIS LINE AND THE LINES ABOVE SSL_REDIRECT:connectwithme.in
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_URI} !^/?assets/.+$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php !-f #add this for any kind of file extension. If you want to display .html, then you will have to add .html also
RewriteCond %{REQUEST_URI} !^/?assets/.+$ [NC]
RewriteCond %{REQUEST_URI} !^/?show_tmp$ [NC]
RewriteRule (.*) https://%{HTTP_HOST}/show_tmp?tmp=$1 [NC,L,QSA,P]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^.]+)$ $1.php [NC,L]
当有人输入https://testing.in/abcval,那么你想要什么https://testing.in/show_tmp?tmp=abcval 内部显示执行情况?如果有人直接访问会发生什么https://testing.in/show_tmp?tmp=abcval?@vivek_23如果有人直接打开页面https://testing.in/show_tmp?tmp=abcval 它显示了正确的page@NitinJohnson现在,,你能删除所有其他的规则,然后用这个来测试吗?另外,测试隐姓埋名模式。如你所说,尝试了,但仍然面临着相同的问题,它显示404page@NitinJohnson当它给你一个404时,URL是什么?@NitinJohnson好的,你能在添加我的脚本时显示完整的.htaccess文件吗?让我们看看。
# DO NOT REMOVE THIS LINE AND THE LINES BELOW SSL_REDIRECT:connectwithme.in
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^connectwithme.in$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# DO NOT REMOVE THIS LINE AND THE LINES ABOVE SSL_REDIRECT:connectwithme.in
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_URI} !^/?assets/.+$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php !-f #add this for any kind of file extension. If you want to display .html, then you will have to add .html also
RewriteCond %{REQUEST_URI} !^/?assets/.+$ [NC]
RewriteCond %{REQUEST_URI} !^/?show_tmp$ [NC]
RewriteRule (.*) https://%{HTTP_HOST}/show_tmp?tmp=$1 [NC,L,QSA,P]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^.]+)$ $1.php [NC,L]