删除子目录&删除 htaccess 中的 .php 扩展名不起作用?
我是 url 重写的新手:
首先,这是我想要完成的任务: 当前 URL:www.example.com/subdirectory1/subdirectory2/something.php
所需 URL:www.example.com/subdirectory1/something/
而且,subdirectory2 的名称是固定的。
可能的?
我当前的 htaccess 只是删除“.php”但也不起作用。 (知道如何调试 htaccess 吗?)
RewritEngine on
RewriteCond %{REQUEST_URI} !\.php$ [NC]
RewriteCond %{REQUEST_URI} [^/]$
RewriteRule ^(.*)$ $1.php [L]
RewriteRule ^(?!subdirectory1/|subdirectory2/)(.+)$ subdirectory1/$1 [L]
谢谢。
I m new to url rewrite:
First, here is what I am trying to accomplish:
Current URL: www.example.com/subdirectory1/subdirectory2/something.php
Desired URL: www.example.com/subdirectory1/something/
And, the name of subdirectory2 is fixed.
Possible?
My current htaccess just to remove the ".php" but also not working. (Any idea how to debug htaccess??)
RewritEngine on
RewriteCond %{REQUEST_URI} !\.php$ [NC]
RewriteCond %{REQUEST_URI} [^/]$
RewriteRule ^(.*)$ $1.php [L]
RewriteRule ^(?!subdirectory1/|subdirectory2/)(.+)$ subdirectory1/$1 [L]
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的第一个问题是
RewritEngine on
。你少了一个e。应该是RewriteEngine on
。试试这个:
这仅适用于完全您所说的内容。固定总是一样的。将其替换为正确的值。
用户访问:
www.example.com/1234/fixed/5678.php
。他被重定向到www.example.com/1234/5678
用户转到
www.example.com/1234/5678
。在服务器上,这将变为www.example.com/1234/fixed/5678.php
。像
www.example.com/1234/5678/9abcd
这样的东西将不起作用。 (超过两级目录。)Your first problem is
RewritEngine on
. You are missing an e. Should beRewriteEngine on
.Try this:
This only works for exactly what you said. Fixed is always the same. Replace it with the correct value.
The users goes to:
www.example.com/1234/fixed/5678.php
. He is redirected towww.example.com/1234/5678
User goes to
www.example.com/1234/5678
. On the server, this becomeswww.example.com/1234/fixed/5678.php
.Something like
www.example.com/1234/5678/9abcd
will not work. (More than two levels of directories.)