简体   繁体   English

Seo友好的URL与.htaccess

[英]Seo-Friendly url's with .htaccess

I already found several topics and questions regarding this, but it seems everything I'm trying to do doesn't do what it is supposed to do: 我已经找到了一些与此相关的主题和问题,但似乎我尝试做的所有事情都没有实现应做的事情:

.htaccess-file 的.htaccess文件

Options +FollowSymLinks

RewriteEngine On
RewriteBase /
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?site=$1 

As you can tell, nothing to special. 如您所知,没什么特别的。 This example was taken from this solution here: SEO Friendly URL (with .htaccess) 此示例来自以下解决方案: SEO友好URL(带有.htaccess)

From my example: 从我的例子:

http://example.org/index.php?site=delivery

should result in 应该导致

http://example.org/Delivery # If it is possible, a capitalized Letter would be cool

I can call the Site manually, but references (to *.css-files) aren't included anymore. 我可以手动调用该站点,但是不再包含对* .css文件的引用。 Furthermore, the RewriteBase doesn't seem to work. 此外,RewriteBase似乎不起作用。

I added some buggy code to verify that the .htaccess file is loaded (and it is). 我添加了一些错误代码以验证是否已加载.htaccess文件。

If I linke something with <a href="index.php?site=mySite"> - does the URL automagically change to the specific rule? 如果我用<a href="index.php?site=mySite">链接了某些内容-URL是否自动更改为特定规则? Yes, right? 是的,对吗? But what could be missing, that the rules aren't applying? 但是,规则不适用可能会遗漏什么呢?

Thank you in advance 先感谢您

Your rule is fine. 你的规则很好。 Because of the rewrite, you have to handle relative links differently now. 由于重写,您现在必须以不同的方式处理相对链接。

So once the rule is in place. 因此,一旦规则到位。 You need to add this to the <head> section of your html. 您需要将此添加到html的<head>部分。

<base href="http://www.yoursite.com" />

Then your JS and CSS will load while using the rule. 然后,您将在使用规则时加载JS和CSS。 It's not a .htaccess rule problem. 这不是.htaccess规则问题。

If I linke something with - does the URL automagically change to the specific rule? 如果我使用链接-URL是否会自动更改为特定规则?

No it does not. 不,不是的。 You need a rule for that too. 您也需要一个规则。

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteCond {THE_REQUEST} ^[A-Z]{3,}\ /+index\.php\?site=(.+)
RewriteRule ^ %1? [R=301,L]

RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?site=$1 

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

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