简体   繁体   English

如果URL不只使用符号字母和数字,则匹配GET_URI

[英]Match GET_URI if URL don't use symbols only letters and numbers

Im trying to get the URL of the page what the visitor access example page: https://example.com/sitemap-index.xml 我正在尝试获取访问者访问示例页面的页面URL: https : //example.com/sitemap-index.xml

But i want to check ( for protection ) if /sitemap-(A1).xml A1 - Is only letters or numbers 但我想检查/(保护)/ sitemap-(A1).xml A1-仅是字母还是数字

Example of good URLs 良好网址的示例

https://example.com/sitemap-index.xml https://example.com/sitemap-index.xml

https://example.com/sitemap-1.xml https://example.com/sitemap-1.xml

https://example.com/sitemap-2.xml https://example.com/sitemap-2.xml

Example of bad URLs 错误网址示例

https://example.com/sitemap-ind-ex.xml https://example.com/sitemap-ind-ex.xml

I try using this PHP command 我尝试使用此PHP命令

 $GET_URI = $_SERVER['REQUEST_URI'];
 if(preg_match('/\/sitemap-[^A-Za-z0-9].xml/', $GET_URI)) {
  $Page_Type = 'Sitemap';
 }

How i can fix this, so i can match the good pages? 我该如何解决这个问题,以便能匹配好的页面?

After checking what im doing wrong ... i success to fix it this way 在检查我做错了什么之后...我成功解决了这种问题

 if(preg_match('/\/sitemap-([A-Za-z0-9]+).xml/', $GET_URI)) {

 }

If someone needs ... 如果有人需要...

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

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