2014-11-08 54 views
0

我看到使用href="blaah"代替href="blaah.php"ahref属性标签。我也看到href=".."代替href="index.php"HREF的= “blaah” 代替HREF = “blaah.php” 和HREF = “..”,而不是HREF = “的index.php”

我已经在NGINX服务器上测试了这个,但是当我主持时,我可能最终会通过Apache进行托管。那么,是否支持Apache href="blaah"

+0

您正在引用一种称为URL重写的技术:http://stackoverflow.com/questions/2433545/how-to-make-extension-less-url-for-a-php-based-site – HaukurHaf 2014-11-08 16:34:35

+0

而大多数时间,诸如'http:// example.com/news /'等URL可以(而且应该)被用来代替'http:// example.com/news/index.php'。 – 2014-11-08 16:40:08

回答

1

您可以使用RewriteEngine,只需将此代码添加到您的.htaccess。

RewriteEngine On 
RewriteBase/

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

此代码将.php添加到没有扩展名的每个文件。

+0

怎么样使用'href =“..”'而不是'href =“index.php”' – Ben 2014-11-08 17:04:26

+0

*没关系,这已经在Apache中起作用了。 – Ben 2014-11-08 17:14:54