所以我遇到了一个问题。我想制作这个网址https://example.com/l/click.php?id=something
看起来像这样https://example.com/l/something
有谁知道如何使它发生在每个代码中?
我尝试编辑和使用此示例.htaccess代码,但它不起作用:/
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?users/(.*?)/?$ /users.php?name=$1 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /users.php?name=([^& ]+)
RewriteRule ^/?users.php$ /users/%1? [L,R=301]
您需要在php 文件所在的目录中的.htaccess文件中实现重写规则。
比如创建一个名为.htaccess的文件,并将下面的代码保存在其中
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ click.php?id=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ click.php?id=$1
在你的 php 上,你会有类似的东西
<a href = "click/$id'></a>
或
<a href = "/$id'></a>
永远记住关闭apache并重新启动它以使其生效
因此,我测试了一些.htaccess代码并制定了我的解决方案。 它非常简单,并且以最佳方式工作!
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ click.php?id=$1 [L]
如果您想自己使用它,只需将click.php
更改为您自己的PHP文件