Htaccess 删除部分 URL

发布于 2025-01-02 10:35:01 字数 344 浏览 1 评论 0原文

我有这个网址: http://www.website.nl/pagina/ 4/wie-ben-ik.html

“pagina”是一个真正的php文档。 “4”是网页的id,我用这个id从数据库中获取结果。

我可以将此网址更改为 http://www.website.nl/wie-ben-ik 使用 htaccess?

谢谢你!

I have this URL: http://www.website.nl/pagina/4/wie-ben-ik.html

"pagina" is a real php document.
"4" is the id of the webpage, with the id I get the results from the database.

Can I change this URL to http://www.website.nl/wie-ben-ik with htaccess?

Thank you!

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

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

发布评论

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

评论(2

末蓝 2025-01-09 10:35:01

如果您希望从数据库中查询,则必须以某种方式传递 id。

使用查询字符串(名称-值对)或将其放在 URI 中,就像上面所做的那样。

如果您不想在 URI 中包含 pagina,您可以使用如下所示的 URI:
http://www.website.nl/wie-ben-ik/<您要发送的号码>

RewriteCond %{REQUEST_URI} ^/(wie-ben-ik)/(\d+)
RewriteRule ^ /pagina/%2/%1\.html

You have to pass the id some way or the other if you want it to query from the database.

Either use a query string (name-value pair) or have it in the URI like your are doing above.

If you do not want pagina in your URI you can have your URI's like this:
http://www.website.nl/wie-ben-ik/<the number you want to send>

RewriteCond %{REQUEST_URI} ^/(wie-ben-ik)/(\d+)
RewriteRule ^ /pagina/%2/%1\.html
本宫微胖 2025-01-09 10:35:01

尝试将以下内容添加到站点根目录中的 .htaccess 文件中。

RewriteEngine on
RewriteBase / 

#redirect http://www.website.nl/pagina/4/wie-ben-ik.html to http://www.website.nl/wie-ben-ik 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /pagina/4/(wie-ben-ik)\.html [NC]       
RewriteRule ^ %1 [L,R=301]

#process wie-ben-ik as http://www.website.nl/pagina/4/wie-ben-ik.html
RewriteRule ^([-a-zA-Z]+)$  pagina/4/$1.html [L,NC] 

Try adding the following to the .htaccess file in the root directory of your site.

RewriteEngine on
RewriteBase / 

#redirect http://www.website.nl/pagina/4/wie-ben-ik.html to http://www.website.nl/wie-ben-ik 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /pagina/4/(wie-ben-ik)\.html [NC]       
RewriteRule ^ %1 [L,R=301]

#process wie-ben-ik as http://www.website.nl/pagina/4/wie-ben-ik.html
RewriteRule ^([-a-zA-Z]+)$  pagina/4/$1.html [L,NC] 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文