.htaccess 和 mod_rewrite 的链接口是心非问题
抱歉,我无法想出更好的标题。
这是我的 htaccess
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L,QSA]
这是我的问题:
localhost/validpage 给了我 localhost/validpage.php 的内容。 localhost/validpage/blah 也给了我相同的(validpage.php)页面, localhost/validpage/blah/blah/... 因此,我面临的问题是链接口是心非(用我的话来说!)。
如何允许仅从 localhost/validpage
访问 localhost/validpage.php
,而不是其他内容,甚至不从 localhost/validpage.php
访问。
我也开始了关于 *Server****Fault*** 的问题,但是但没有取得多大成功。 我得到的答案是仅用 htaccess 无法完成。
我所说的有效页面是指服务器上的任何有效页面。由于我正在使用 mod_rewrite 改造现有网站以获得更清晰的网址,因此我正在寻找一个相对简单的解决方案,最好仅使用 .htaccess。但是,任何解决方案都是受欢迎的。
Sorry I couldn't come up with a better title.
Here is my htaccess
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L,QSA]
And this is my problem:
localhost/validpage gives me the contents of localhost/validpage.php.
localhost/validpage/blah also gives me the same (validpage.php) page and so does localhost/validpage/blah/blah/...
Therefore the problem I am facing is link duplicity(in my words!).
How do I allow localhost/validpage.php
to be accessed from localhost/validpage
only and nothing else, not even localhost/validpage.php
.
I have started a question on *Server****Fault*** too but with not much success.
The answer I have got is it cannot be done with htaccess alone.
By validpage I mean any valid page on the server. Since I am retrofitting an existing site with mod_rewrite for cleaner urls, I am looking for a relatively easy solution preferably with .htaccess only. However, any solutions are welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的图像等的来源属性是什么???
绝对还是相对?
和
指向不同的文件应用重写规则时。
what is the source attribute of your images, etc ???
absolute or relative?
<img src="/images/my.jpg" />
and<img src="images/my.jpg" />
point to different files when applying your rewrite rules.您可以尝试在 .htaccess 中使用它,
我应该将您的 php 脚本重写为友好的 url,并使用 .php 扩展名重定向请求。
You could try using this in your .htaccess
I should rewrite your php scripts to friendly urls, and redirect requests using the .php extension.