htaccessでURLからページエイリアスを削除するにはどうすればよいですか?
私は自分のcmsを作成しましたが、次の問題が見つかりました。ページのリンクは次のように表示されます。
https://www.example.com/page/contact-us
ページエイリアスを削除して、次のように表示したいと思います。
https://www.example.com/contact-us
私のHtaccess:
オプション-MultiViews RewriteEngineオン RewriteRule ^ page /([\ s \ S] *)$ single-page.php?slug=$1 [L]
私はこれを試しましたが、うまくいきません
RewriteEngineオン RewriteRule ^([^ /] *)$ /page/single-page.php?slug=$1 [L]
回答
2 anubhava
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]