【发布时间】:2014-03-24 18:29:15
【问题描述】:
我正在重写我的网址以摆脱 .php 扩展名(希望 get 变量也是如此,因为我得到的所有帮助都很棒,但仍然无法正常工作。
这是我的代码:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php[\s?] [NC]
RewriteRule ^ %1 [R=301,L]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+?)/?$ $1.php [NC,L]
现在,当我使用此代码时,它会将 .php 取出,但随后错误提示:
Not Found
The requested URL /index.php was not found on this server.
同时,如果我取出该代码,它可以正常工作,但具有 .php 扩展名
【问题讨论】:
-
好吧,你隐藏 .php 并在之后请求它。没有扩展就找不到它。我建议在之后隐藏扩展。
-
@KRUKUSA 如果我这样做,它会将我重定向到我的本地主机核心文件(MAMP 本地主机屏幕)
-
我对此不太满意,但如果你在其中抛出一个语句,比如 if / contains .php replace with .....
-
只有你想隐藏扩展名?或者你想要更多的东西?
标签: php html apache .htaccess url