将子目录中的任何内容重定向到绝对目录路径

时间:2016-10-05 19:07:28

标签: apache mod-rewrite

使用RewriteRule我试图将子目录中的每个url重定向到另一个子目录作为绝对路径,修剪第一个目录之后的任何内容。例如:

www.domain.com/store/search
www.domain.com/store/search?search=some_term

所有人都需要去

www.domain.com/newdir /

不幸的是,我看到的结果是这样的:

www.domain.com/store/newdir/
www.domain.com/store/newdir/?search=some_term

等等。我目前正在使用此命令:

重写发动机 RewriteRule搜索(。*)newdir / [R = 301,NC,L]

如何将/ store / search中的任何内容重定向到简单/ newdir,修剪“搜索”一词之后的所有内容?感谢。

1 个答案:

答案 0 :(得分:1)

如果.htaccess位于根目录中,您可以执行类似这样的操作

Started by user eugene
Building in workspace /Users/Shared/Jenkins/Home/jobs/test_2/workspace
[WS-CLEANUP] Deleting project workspace...
[WS-CLEANUP] Done
Cloning the remote Git repository
Cloning repository http://eugene@localhost:7990/scm/test/test_01.git
 > git init /Users/Shared/Jenkins/Home/jobs/test_2/workspace # timeout=10
Fetching upstream changes from http://eugene@localhost:7990/scm/test/test_01.git
 > git --version # timeout=10
 > git fetch --tags --progress http://eugene@localhost:7990/scm/test/test_01.git +refs/heads/*:refs/remotes/origin/*
 > git config remote.origin.url http://eugene@localhost:7990/scm/test/test_01.git # timeout=10
 > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git config remote.origin.url http://eugene@localhost:7990/scm/test/test_01.git # timeout=10
Fetching upstream changes from http://eugene@localhost:7990/scm/test/test_01.git
 > git fetch --tags --progress http://eugene@localhost:7990/scm/test/test_01.git +refs/heads/*:refs/remotes/origin/*
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision 0dd6cdb03e3cbf01918ed160b54ff85c44cdbf6f (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 0dd6cdb03e3cbf01918ed160b54ff85c44cdbf6f
 > git rev-list 0dd6cdb03e3cbf01918ed160b54ff85c44cdbf6f # timeout=10
[workspace] $ mvn package docker:build
FATAL: command execution failed
java.io.IOException: Cannot run program "mvn" (in directory "/Users/Shared/Jenkins/Home/jobs/test_2/workspace"): error=2, No such file or directory
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
    at hudson.Proc$LocalProc.<init>(Proc.java:243)
    at hudson.Proc$LocalProc.<init>(Proc.java:212)
    at hudson.Launcher$LocalLauncher.launch(Launcher.java:815)
    at hudson.Launcher$ProcStarter.start(Launcher.java:381)
    at hudson.Launcher$ProcStarter.join(Launcher.java:388)
    at hudson.tasks.Maven.perform(Maven.java:363)
    at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:779)
    at hudson.model.Build$BuildExecution.build(Build.java:205)
    at hudson.model.Build$BuildExecution.doRun(Build.java:162)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:534)
    at hudson.model.Run.execute(Run.java:1720)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:98)
    at hudson.model.Executor.run(Executor.java:404)
Caused by: java.io.IOException: error=2, No such file or directory
    at java.lang.UNIXProcess.forkAndExec(Native Method)
    at java.lang.UNIXProcess.<init>(UNIXProcess.java:248)
    at java.lang.ProcessImpl.start(ProcessImpl.java:134)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
    ... 15 more
Build step 'Invoke top-level Maven targets' marked build as failure
Finished: FAILURE

或者.htaccess是否在&#34;商店&#34;目录你可以这样做......

RewriteEngine on
RewriteRule ^store/search(.*)?$ ./newdir/$1 [R=301,NC,L]

以上是保留查询字符串,如果你只想重定向到目录删除$ 1