【发布时间】:2016-05-05 11:56:03
【问题描述】:
我在根目录中使用了我所有的 uls,现在我无法更改所有这些,所以我需要重写隐藏文件夹名称的主 url,如果有人打开该域,则保存在该文件夹中的数据也必须打开,但是文件夹名称不应显示在 url 中,即我有这个
.我想把它改成
但它应该自动获取文件夹名称数据。如何实现 通过使用“.htaccess”文件
RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
这是我当前使用的 .htaccess 文件
【问题讨论】:
-
这个 htaccess 在哪里?是在
/foldername/里面吗? -
这可能会对您有所帮助。看看 - stackoverflow.com/questions/17642122/…
-
是的。你是对的,所以我可以创建一个新的 htaccess 文件来解决我的问题,并且可以保留这个文件,因为它是 @anubhava。
-
这个 htaccess 可以在
foldername中使用,但你需要在 root 中使用另一个 htaccess -
是的@anubhava,所以你能告诉我这是如何实现的吗?另一个 htaccess 没有问题
标签: php .htaccess mod-rewrite url-rewriting