.htaccess:修改 URL
我将网站的大部分公共内容保存在一个名为“pages”的文件夹中,其中每个页面都有一个文件夹,然后在每个页面中我都有针对每种内容类型的文件夹。
编辑:重写它以使其更容易理解。
所以我的典型 URL 是: http://www.example.co.uk/folderName/folderName/folderName/fileName.php
但我希望它显示如下: http:// /www.example.co.uk/fileName
我还需要 URL 来处理粘在其末尾的 PHP 变量,如下所示:http://www.example.co.uk /fileName?phpVar=1
我知道这是可能的,因为我看到到处都是这样做的。 :L
I keep most of my website's public content in a folder named "pages", inside there I have a folder for each page, then inside each of those I have folders for each type of content.
Edit: Rewrote it to be more understandable.
So my typical URL is: http://www.example.co.uk/folderName/folderName/folderName/fileName.php
But I would like it to display like this: http://www.example.co.uk/fileName
I would also need to URL to be work with PHP variables stuck on the end of it, like so: http://www.example.co.uk/fileName?phpVar=1
I know it's possible, as I see it done everywhere. :L
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许是这个?
Maybe this?
应该做你正在寻找的事情。假设您希望用户将
http://example.com/about.php
视为http://example.com/about
。添加
RewriteCond %{REQUEST_FILENAME} !-d
可能也是必要的,但从您的描述中尚不清楚。要让您的主页始终在 url 中显示“home”,您需要在索引文件中使用类似以下内容:
然后将其添加到您的 .htaccess 文件中:
Should do what you're looking for. Assuming you want
http://example.com/about.php
to be seen ashttp://example.com/about
by the users.Adding
RewriteCond %{REQUEST_FILENAME} !-d
might be necessary, too, but it's not clear from your description.To get your home page to always show "home" in the url, you'll want to use something like the following in your index file:
And then add this to your .htaccess file: