.htAccess url을 서브 디렉토리로 다시 작성합니다
-
21-08-2019 - |
문제
아래에서 "/socdir"to "/socdir/projects"아래에있는 모든 것을 다시 작성하는 가장 좋은 방법은 다음과 같습니다.
http://www.mydomain.com/some/subidr/test/
... 이에:
http://www.mydomain.com/some/subdir/projects/test/
나는 a를 찾았다 비슷한 질문 게시되었지만 솔루션이 제 경우에는 작동하지 않은 것 같습니다. 지금까지의 나의 시도 (작동하지 않는 것 같다) :
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/projects/.*$
RewriteRule ^(.*)$ /projects/$1 [L]
편집하다: 서버의 웹 루트에 대한 쓰기 액세스가 없으므로 .htaccess 파일이 /sod /subdir 내에 앉아 있어야한다고 언급하는 것을 잊었습니다.
해결책
이것은 내가 마침내 일해야 할 해결책입니다.
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/some/subdir/projects/.*$
RewriteRule ^(.*)$ /some/subdir/projects/$1 [L]
다른 팁
서버의 문서 루트에서 .htaccess 구성 파일 에서이 규칙을 시도하십시오.
RewriteEngine on
RewriteRule !^some/subdir/projects(/|$) some/subdir/projects%{REQUEST_URI} [L]
이 규칙을 사용하고 싶을 때 /some/subdir/
디렉토리, 다음과 같이 규칙을 변경하십시오.
RewriteRule !^projects(/|$) projects%{REQUEST_URI} [L]
요청을 리디렉션하려면 /some/subdir/projects/
foobar
에게 /some/subdir/
foobar
,이 규칙을 앞에서 언급 한 것보다 위에 올려 놓으십시오.
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /some/subdir/projects[/?\s]
RewriteRule ^some/subdir/projects/?([^/].+)?$ /some/subdir/$1 [L,R=301]
나는 이것을 사용한다 :
RewriteEngine On
RewriteRule ^(/some/subdir)/(.*)$ $1/projects/$2
이것은 리디렉션됩니다 /some/subdir/<anything>
에게 /some/subdir/projects/<anything>
.
선두에 주목하십시오 /
실제로 URL의 시작과 일치하는 데 필요합니다. ~하지 않는 한 당신은 가지고 있습니다 RewriteBase /
어딘가에 설정하십시오.
제휴하지 않습니다 StackOverflow