我看到使用href="blaah"
代替href="blaah.php"
为a
的href
属性标签。我也看到href=".."
代替href="index.php"
。HREF的= “blaah” 代替HREF = “blaah.php” 和HREF = “..”,而不是HREF = “的index.php”
我已经在NGINX服务器上测试了这个,但是当我主持时,我可能最终会通过Apache进行托管。那么,是否支持Apache href="blaah"
?
我看到使用href="blaah"
代替href="blaah.php"
为a
的href
属性标签。我也看到href=".."
代替href="index.php"
。HREF的= “blaah” 代替HREF = “blaah.php” 和HREF = “..”,而不是HREF = “的index.php”
我已经在NGINX服务器上测试了这个,但是当我主持时,我可能最终会通过Apache进行托管。那么,是否支持Apache href="blaah"
?
您可以使用RewriteEngine,只需将此代码添加到您的.htaccess。
RewriteEngine On
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+)$ $1.php [L]
此代码将.php添加到没有扩展名的每个文件。
您正在引用一种称为URL重写的技术:http://stackoverflow.com/questions/2433545/how-to-make-extension-less-url-for-a-php-based-site – HaukurHaf 2014-11-08 16:34:35
而大多数时间,诸如'http:// example.com/news /'等URL可以(而且应该)被用来代替'http:// example.com/news/index.php'。 – 2014-11-08 16:40:08