简体   繁体   English

htaccess用于SEO友好的网址

[英]htaccess for SEO friendly urls

So for two days I can not understand why this won't work...: 所以有两天我不明白为什么这行不通...:

  Options -Indexes 
  Options +FollowSymLinks
  RewriteEngine On
  RewriteRule ^advice/([a-zA-Z]+)/([0-9]+)/$ advice.php?advice=$1&id=$2

Obviously .htaccess is allowed since I am not able to directory open folders, but why doesn't the link work? 显然.htaccess是允许的,因为我无法对打开的文件夹进行目录设置,但是为什么链接不起作用?

Try turning off multiviews so the server doesn't try and search for that as a file. 尝试关闭multiviews这样服务器就不会尝试将其作为文件搜索。 In addition add the conditions so that it knows it's not looking for a real file or directory it's trying to serve and make the trailing slash optional. 另外,添加条件,以便它知道它不是在寻找要提供的真实文件或目录,并且使斜杠成为可选。

  Options -Indexes +FollowSymLinks -MultiViews
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^advice/([a-zA-Z]+)/([0-9]+)/?$ /advice.php?advice=$1&id=$2 [L]

Does your RewriteRule redirect to an existing file? 您的RewriteRule是否重定向到现有文件? Try this, it works for me 试试这个,对我有用

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /test2/test.php
  • http://example.com/test2/.htaccess shows the location of the .htaccess file http://example.com/test2/.htaccess显示.htaccess文件的位置
  • http://example.com/test2/test.php is a direct link http://example.com/test2/test.php是直接链接
  • http://example.com/test2/testX4XX opens the same test.php file using rewrite http://example.com/test2/testX4XX使用重写打开相同的test.php文件

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

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