重写url导致重复页面

发布于 2024-09-16 10:55:18 字数 734 浏览 3 评论 0原文

我尝试重写我的 url,以便删除 php 扩展名并添加尾部斜杠。

我现在可以通过这种方式访问​​该页面.. lovelakedistrict.com/lake-district-cottages/

但我也可以通过以下方式访问它:

lovelakedistrict.com/lake-district-cottages.php

如何永久删除 php 扩展名。这是我的 htaccess

Options +FollowSymlinks
Options +Indexes
RewriteEngine on
RewriteBase /



RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]




RewriteRule ^lake-district-cottages/cottages/([0-9]) lake-district-cottages.php?cottages=$1

I have tried to rewrite my url so that it removes php extention and adds trailing slash.

I can access the page this way now..
lovelakedistrict.com/lake-district-cottages/

but i can also access it via this way:

lovelakedistrict.com/lake-district-cottages.php

how can I remove the php extention for good. this my htaccess

Options +FollowSymlinks
Options +Indexes
RewriteEngine on
RewriteBase /



RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]




RewriteRule ^lake-district-cottages/cottages/([0-9]) lake-district-cottages.php?cottages=$1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

疯到世界奔溃 2024-09-23 10:55:19
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^.#?\ ]+\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^([^.]+)\.php$ /$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^.#?\ ]+\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^([^.]+)\.php$ /$1 [R=301,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文