2013-03-30 71 views
0

我想知道如何使用.htaccess从网址完全隐藏文件名。如何使用.htaccess从网址隐藏文件名

目前,它是这样的: mysite.com/foldername/filename

而且我想它是这样的: mysite.com/foldername

在我使用.htacces文件去除时刻只有来自url的文件扩展名,我想将其升级为只显示文件夹名称。我们还没有任何有关.htacces的领导,所以我会很感激直接的代码和提示,谢谢! :)

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] 
+0

你需要能够访问多个不同的文件名,或只是其中之一? –

+0

多个文件名 – Defain

+0

“我们还没有任何关于.htacces的领导者” - 我们更喜欢在进入这里提问之前进行一些基础研究。谢谢。 – Kev

回答

2
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' 

别人是一样的
以及有关拉斯部分idont知道。

<br /> 
<br /> 

而且还有一点和问题
如你所说
目前,它是这样的:mysite.com/foldername/filename
而且我想它是这样的:mysite.com /文件夹名称
告诉我它背后有什么样的规则?
你想有这样的

 

    mysite.com/something 

insted的的

 

    mysite.com/something/something.php 

或使用

 

    mysite.com/something 

insted的的

 

    mysite.com/something/anotherthing.php 

如果你想使用第一种方式。
你可以使用这个可能是作品

 

    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 

或者也许这

 

    RewriteCond %{REQUEST_FILENAME} !-d # if requested uri is not directory (!-d) 
    RewriteRule ^([A-Za-z0-9-]+)/?$ $1/$1.php [NC,L] # foldername/foldername.php 

+0

基本上我只想隐藏URL中的文件名,只显示它到文件夹名称,我们还没有研究过这个东西,所以它看起来不像我太熟悉。所以我的意思是你写的第一个关于 – Defain

+0

我有一个建议,为什么你不重命名文件index.php.if你这样做,没有必要使用.htaccess的all.like这个。 mysite /文件夹名称,并加载mysite/foldername/index.php。你的目的是什么? – ncm

+0

我有其他文件名下相同的文件夹名称,不能全部索引 – Defain