[英]Htaccess Remove part of URL
I have this URL: http://www.website.nl/pagina/4/wie-ben-ik.html 我有这个网址: http : //www.website.nl/pagina/4/wie-ben-ik.html
"pagina" is a real php document. “ pagina”是一个真实的php文档。 "4" is the id of the webpage, with the id I get the results from the database. “ 4”是网页的ID,该ID是我从数据库中获得的结果。
Can I change this URL to http://www.website.nl/wie-ben-ik with htaccess? 我可以使用htaccess将这个URL更改为http://www.website.nl/wie-ben-ik吗?
Thank you! 谢谢!
You have to pass the id some way or the other if you want it to query from the database. 如果要从数据库查询,则必须以某种方式传递ID。
Either use a query string (name-value pair) or have it in the URI like your are doing above. 使用查询字符串(名称/值对)或像上面一样将其包含在URI中。
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>
如果您不想在URI中使用pagina
,则可以使用如下所示的URI: http://www.website.nl/wie-ben-ik/<the number you want to send>
: 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
Try adding the following to the .htaccess
file in the root directory of your site. 尝试将以下内容添加到网站根目录中的.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]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.