我想知道如何使用 .htaccess 从 url 中完全隐藏文件名.
目前是这样的:mysite/文件夹名/文件名
我希望它是这样的:mysite/文件夹名
目前我使用 .htacces 文件仅从 url 中删除文件扩展名,我想将其升级为仅显示文件夹名称.我们还没有领导任何关于 .htacces 的事情,所以我很感激非常直接的代码和提示,谢谢!:)
RewriteOptions 继承重写引擎开启RewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME}.php -f重写规则 ^(.*)$ $1.phpRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME}.html -f重写规则 ^(.*)$ $1.htmlRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME}.htm -f重写规则 ^(.*)$ $1.htmRewriteCond %{HTTP_HOST} ^.*$RewriteRule ^/?$ "tjmediaproductions/quiz/" [R=301,L] 解决方案 RewriteOptions inheritRewriteEngine On # 启用 url 重写RewriteCond %{REQUEST_FILENAME} !-d # 如果请求的 uri 不是目录 (!-d)RewriteCond %{REQUEST_FILENAME}.php -f # 如果有一个名为 URI+'.php' 的文件 (-f)RewriteRule ^(.*)$ $1.php # 那么如果uri中有任何东西则将其重写为uri+'.php'其他都一样还有那部分我不知道.
<br/>还有一点和问题如你所说目前它是这样的:mysite/foldername/filename我希望它是这样的:mysite/foldername告诉我它背后有什么样的规则?你想要这个吗
mysite/某事插入
mysite/something/something.php或使用
mysite/某事插入
mysite/something/anotherthing.php如果你想使用第一种方式.你可以使用这可能是有效的
RewriteCond %{REQUEST_FILENAME} -d # 如果请求的 uri 是目录 (-d)RewriteCond %{REQUEST_FILENAME}.php !-f # 如果没有文件 (!-f)RewriteRule ^([A-Za-z0-9-]+)/?$ $1/$1.php [NC,L] # 文件夹名/文件夹名.php或者这个
RewriteCond %{REQUEST_FILENAME} !-d # 如果请求的 uri 不是目录 (!-d)RewriteRule ^([A-Za-z0-9-]+)/?$ $1/$1.php [NC,L] # 文件夹名/文件夹名.phpI was wondering how I could hide filename completetely from url using .htaccess.
Currently it is like: mysite/foldername/filename
And I would like it to be like: mysite/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 ^/?$ "tjmediaproductions/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/foldername/filename And I would like it to be like: mysite/foldername tell me what kind of rule is behind it? do you want to have this
mysite/somethinginsted of
mysite/something/something.phpor use
mysite/somethinginsted of
mysite/something/anotherthing.phpif 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.phpor 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 中隐藏文件名
发布评论