简体   繁体   English

Url重写所有相同的文件名

[英]Url rewriting for all identical filenames

I would like to rewrite all my URL's like so: 我想重写我的所有网址:

http://example.com/folder/40/name/test.php
and
http://example.com/folder/40/test.php

to

http://example.com/test.php

Does anyone have a solution? 有没有人有办法解决吗?

thanks 谢谢

You can do that by using htaccess. 你可以使用htaccess来做到这一点。 It will redirect all urls like 它将重定向所有网址

http://example.com/folder/40/name/test.php
http://example.com/folder/40/test.php

to

http://example.com/test.php

In the htaccess file add below lines 在htaccess文件中添加以下行

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !(img|anyother folders that you want to ignore|anyother folders that you want to ignore|...)
RewriteRule ^(.*)/(.*)/(.*)/test.php$ test.php [L]

RewriteCond %{REQUEST_FILENAME} !(img|anyother folders that you want to ignore|anyother folders that you want to ignore|...)
RewriteRule ^(.*)/(.*)/test.php$ test.php [L]

more information Htaccess Rewrites 更多信息Htaccess重写

You can easily do it by PHP but you have to include this code in both pages before opening HTML tag. 您可以通过PHP轻松完成,但在打开HTML标记之前必须在两个页面中包含此代码。

<?php
$useragent=$_SERVER['HTTP_USER_AGENT'];
header('Location: http://example.com/test.php'); ?>

Hope this will help you! 希望这个能对您有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM