如何通过使用的.htaccess来隐藏URL文件名 [英] How to hide filename from url by using .htaccess
问题描述
我想知道我怎么可以隐藏文件名completetely从URL使用的.htaccess。
目前是这样的: mysite.com/foldername/filename
和我想它是这样的: mysite.com/foldername
目前,我用.htacces文件从URL删除只读文件extensios,我想将它升级到只显示文件夹名。我们没有领导关于.htacces任何事情,所以我会AP preciate pretty的直接codeS和提示,谢谢! :)
RewriteOptions继承
RewriteEngine叙述上
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_FILENAME} \ PHP -f
重写规则^(。*)$ $ 1.PHP
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_FILENAME} \。HTML -f
重写规则^(。*)$ $ 1.HTML
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_FILENAME} \。HTM -f
重写规则^(。*)$ $ 1.htm
的RewriteCond%{HTTP_HOST} ^ * $
重写规则^ / $?HTTP \:\ / \ / tjmediaproductions \ .COM \ /测验\ /[R = 301,L]
RewriteOptions继承
RewriteEngine叙述在#使URL重写
的RewriteCond%{} REQUEST_FILENAME!-d#如果请求的URI不是目录(!-d)
的RewriteCond%{REQUEST_FILENAME} \。PHP的-f#,如果有一个名为URI +。PHP的'文件(-f)
重写规则^(。*)$ $ 1.PHP#那么如果在URI中的任何事,那么它改写为URI +。PHP的
别人都一样
而对拉斯部分idont知道了。
< BR />
< BR />
和还有一点和问题
如你所说
目前,它是这样的:mysite.com/foldername/filename
而且我想它是这样的:mysite.com/foldername
告诉我是什么样的规则是落后吗?
你想有这样的
mysite.com/something
的
insted的
mysite.com/something/something.php
或使用
mysite.com/something
的
insted的
mysite.com/something/anotherthing.php
如果你想使用第一种方式。
你可以使用这个可能是作品
的RewriteCond%{} REQUEST_FILENAME -d#如果请求的URI是目录(-d) 的RewriteCond%{REQUEST_FILENAME} \。的php!-f#和如果没有一个文件(!-f) 重写规则^([A-ZA-Z0-9 - ] +)?/ $ $ 1 / $ 1.PHP [NC,L]#文件夹名/ foldername.php
也许这
的RewriteCond%{} REQUEST_FILENAME!-d#如果请求的URI不是目录(!-d) 重写规则^([A-ZA-Z0-9 - ] +)?/ $ $ 1 / $ 1.PHP [NC,L]#文件夹名/ foldername.php
I was wondering how I could hide filename completetely from url using .htaccess.
Currently it is like: mysite.com/foldername/filename
And I would like it to be like: mysite.com/foldername
At the moment I use .htacces file for removing only file extensios from url and I would like to upgrade it to only show folder name. We have not leader anything about .htacces yet so I would appreciate pretty direct codes and hints, thank you! :)
RewriteOptions inherit
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.htm -f
RewriteRule ^(.*)$ $1.htm
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^/?$ "http\:\/\/tjmediaproductions\.com\/quiz\/" [R=301,L]
RewriteOptions inherit
RewriteEngine On # enables url rewriting
RewriteCond %{REQUEST_FILENAME} !-d # if requested uri is not directory (!-d)
RewriteCond %{REQUEST_FILENAME}\.php -f # and if there is a file named URI+'.php' (-f)
RewriteRule ^(.*)$ $1.php # then if there is any thing in uri then rewrite it as uri+'.php'
others are the same
and about the las part idont know.
<br />
<br />
and there is another point and question
as you said
Currently it is like: mysite.com/foldername/filename
And I would like it to be like: mysite.com/foldername
tell me what kind of rule is behind it?
do you want to have this
mysite.com/something
insted of
mysite.com/something/something.php
or use
mysite.com/something
insted of
mysite.com/something/anotherthing.php
if you want to use first way.
you can use this may be works
RewriteCond %{REQUEST_FILENAME} -d # if requested uri is directory (-d) RewriteCond %{REQUEST_FILENAME}\.php !-f # and if there is not a file (!-f) RewriteRule ^([A-Za-z0-9-]+)/?$ $1/$1.php [NC,L] # foldername/foldername.php
or maybe this
RewriteCond %{REQUEST_FILENAME} !-d # if requested uri is not directory (!-d) RewriteRule ^([A-Za-z0-9-]+)/?$ $1/$1.php [NC,L] # foldername/foldername.php
这篇关于如何通过使用的.htaccess来隐藏URL文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!