删除子目录&删除 htaccess 中的 .php 扩展名不起作用?

发布于 2024-10-24 13:10:05 字数 507 浏览 0 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

つ可否回来 2024-10-31 13:10:05

您的第一个问题是RewritEngine on。你少了一个e。应该是RewriteEngine on

试试这个:

RewriteEngine on 

# Remove .php
RewriteCond %{REQUEST_URI} \.php$
RewriteRule ^([^/]+)/fixed/([^/]+).php$ /$1/$2/ [R=301,L]

# Rewrite "friendly" URL into php.
RewriteRule ^([^/]+)/([^/]+)/?$ /$1/fixed/$2.php [L]

这仅适用于完全您所说的内容。固定总是一样的。将其替换为正确的值。

用户访问: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 be RewriteEngine on.

Try this:

RewriteEngine on 

# Remove .php
RewriteCond %{REQUEST_URI} \.php$
RewriteRule ^([^/]+)/fixed/([^/]+).php$ /$1/$2/ [R=301,L]

# Rewrite "friendly" URL into php.
RewriteRule ^([^/]+)/([^/]+)/?$ /$1/fixed/$2.php [L]

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 to www.example.com/1234/5678

User goes to www.example.com/1234/5678. On the server, this becomes www.example.com/1234/fixed/5678.php.

Something like www.example.com/1234/5678/9abcd will not work. (More than two levels of directories.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文