简体   繁体   English

.htaccess中的SEO友好URL重写

[英]SEO-friendly URL rewrite in .htaccess

Before you flag this question -- I did search for answers, and found one close to mine that was not answered directly, so... 在您举报这个问题之前-我确实在寻找答案,并在我附近找到了一个未直接回答的答案,所以...

I am trying to write a simple RewriteRule in my .htaccess file to change ONLY the links that match to an SEO-friendly format. 我正在尝试在我的.htaccess文件中编写一个简单的RewriteRule,以仅更改与SEO友好格式匹配的链接。

RewriteEngine On
RewriteRule ^/includes/seo.([a-zA-Z]+).php$ /$1

So if I have a file 所以如果我有一个文件

/includes/seo.mydocument.php

it will appear in the browser as 它将在浏览器中显示为

/mydocument

Not sure what I'm missing. 不知道我在想什么。

Leading slash is not matched in .htaccess rules so use this .htaccess规则中的前导斜杠不匹配,请使用此

RewriteRule ^includes/seo\.([a-zA-Z]+)\.php$ /$1 [L,R]

But probably you want this: 但是可能您想要这样:

RewriteEngine On

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+includes/seo\.([^.]+)\.php[/\s?] [NC]
RewriteRule ^ /%1? [R=302,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)/?$ /includes/seo.$1.php [L]

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

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