htaccess로 URL에서 페이지 별칭을 제거하는 방법은 무엇입니까?
Nov 14 2020
내 자신의 cms를 만들었고 다음 문제를 발견했습니다. 페이지 링크는 다음과 같이 표시됩니다.
https://www.example.com/page/contact-us
페이지 별칭 을 제거하여 다음과 같이 표시하고 싶습니다 .
https://www.example.com/contact-us
내 Htaccess :
옵션-MultiView RewriteEngine 켜기 RewriteRule ^ page / ([\ s \ S] *)$ single-page.php?slug=$1 [L]
나는 이것을 시도했지만 나를 위해 작동하지 않습니다
RewriteEngine 켜기 RewriteRule ^ ([^ /] *)$ /page/single-page.php?slug=$1 [L]
답변
2 anubhava Nov 14 2020 at 04:46
RewriteRule ^([^/]*)$ /page/single-page.php?slug=$1 [L]
이것은 /page/
분명히 존재하지 않는 디렉토리로 모든 URI를 전달하기 때문에 작동 하지 않습니다.
이 규칙을 사용해야합니다.
# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ single-page.php?slug=$1 [L,QSA]