2013-10-24 188 views
0

我想以这种方式实现url localhost/mysite/contact /没有php扩展名,并在最后添加了尾部斜线但它不工作。删除php文件扩展名

这是代码示例:

RewriteRule ^([^/]+)/$ $1.php 
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$ 
RewriteRule (.*)$ /$1/ [R=301,L] 

我如何能实现如下: 本地主机/ mysite的/页/ 任何帮助吗? 谢谢。

+0

您的PHP是以“http:// localhost/mysite/contact.php”的身份访问的吗? – anubhava

+0

这是正确的。这是http://localhost/mysite/contact.php – test

回答

0

启用通过httpd.confmod_rewrite.htaccess,然后把这个代码在你DOCUMENT_ROOT/.htaccess文件:

RewriteEngine On 
RewriteBase /mysite/ 

RewriteRule ^foo/?$ bar [L,NC,R] 

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

对不起anubhava。这不起作用。 – test

+0

那么当你输入'http:// localhost/mysite/contact'时会发生什么?你有404吗?这也在'DOCUMENT_ROOT/.htaccess'或'DOCUMENT_ROOT/mysite/.htaccess'中? – anubhava

+0

找不到对象! 在此服务器上找不到请求的URL。如果您手动输入网址,请检查拼写并重试。 如果您认为这是服务器错误,请与网站管理员联系。 错误404 localhost Apache/2.4.3(Win32)OpenSSL/1.0.1c PHP/5.4.7 – test

0

确保您已启用国防部重写并加载

如 RewriteEngine叙述上

这将工作没有文件v系统检查开销

RewriteRule ^([^。?] +)$%{REQUEST_URI} .php [L]

+0

全码: RewriteEngine叙述上 RewriteBase/mysite的/ 重写规则^([^。?] +)$%{REQUEST_URI} .PHP [L] test

+0

我已经得到了同样的问题重定向! – test