Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 使用htaccess从URL中删除子目录_.htaccess_Url Rewriting_Rewrite - Fatal编程技术网

.htaccess 使用htaccess从URL中删除子目录

.htaccess 使用htaccess从URL中删除子目录,.htaccess,url-rewriting,rewrite,.htaccess,Url Rewriting,Rewrite,我有以下网址: 使用htaccess,我需要从URL中删除第一个/search,以便URL为: 就我个人而言,我不知道该怎么做。 这是我的htaccess文件的相关部分 # Remove www from URL RewriteCond %{HTTP_HOST} ^www\.example\.org$ [NC] RewriteRule ^(.*)$ http://example.org/$1 [R=301,L] # Remove the need for the php file exte

我有以下网址:

使用htaccess,我需要从URL中删除第一个/search,以便URL为:

就我个人而言,我不知道该怎么做。 这是我的htaccess文件的相关部分

# Remove www from URL
RewriteCond %{HTTP_HOST} ^www\.example\.org$ [NC]
RewriteRule ^(.*)$ http://example.org/$1 [R=301,L]

# Remove the need for the php file extension
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://example.org/$1 [R=302,L]

# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]

# Remove index from home URL
RewriteRule ^(.*)index\.php$ http://%{HTTP_HOST}/$1 [R=301,L]

谢谢

我不知道你的规则是如何运作的。您有一些重复的规则和重定向会干扰路由。将所有重定向放在同一位置,并确保在添加php扩展之前使用
-f
检查:

# Remove www from URL
RewriteCond %{HTTP_HOST} ^www\.example\.org$ [NC]
RewriteRule ^(.*)$ http://example.org/$1 [R=301,L]

# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} \ /+(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://example.org/$1 [R=302,L]

# Remove index from home URL
RewriteCond %{THE_REQUEST} \ /+(.*)index\.php
RewriteRule ^(.*)index\.php$ http://%{HTTP_HOST}/$1 [R=301,L]

# Remove the search folder:
RewriteCond %{THE_REQUEST} \ /+search/search
RewriteRule ^search/search(.*)$ /search$1 [L,R=301]

# Add the search folder back
RewriteCond $1 !^/search
RewriteRule ^search(.*)$ /search/search$1 [L]

# Add the extension back on if it exists
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]