我是url重写的新手:
首先,这是我想要完成的事情: 当前网址:www.example.com/subdirectory1/subdirectory2/something.php
所需网址:www.example.com/subdirectory1/something /
并且,子目录2的名称是固定的。
可能的?
我目前的htaccess只是删除“.php”但也无法正常工作。 (知道如何调试htaccess ??)
RewritEngine on
RewriteCond %{REQUEST_URI} !\.php$ [NC]
RewriteCond %{REQUEST_URI} [^/]$
RewriteRule ^(.*)$ $1.php [L]
RewriteRule ^(?!subdirectory1/|subdirectory2/)(.+)$ subdirectory1/$1 [L]
感谢。
答案 0 :(得分:0)
您的第一个问题是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
这样的东西不起作用。 (超过两级目录。)