1

私の狙い

入力 URL がそれぞれ以下の場合:

  1. somedomain.p.ht/admin/articles
  2. somedomain.p.ht/admin/comments

予想される書き換え URL はそれぞれ次のとおりです。

  1. somedomain.p.ht/admin/index.php?adminpage=記事
  2. somedomain.p.ht/admin/index.php?adminpage=コメント

public_html フォルダーの .htaccess コード

RewriteEngine On
RewriteBase /

#always use www - redirect non-www to www permanently
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]


# hotlink protection
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?domain.p.ht [NC]
RewriteRule \.(jpg|jpeg|png|gif|css|js)$ - [NC,F,L]

# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

# File caching is another famous approach in optimizing website loading time
<FilesMatch ".(flv|gif|jpg|jpeg|png|ico|swf|js|css|pdf)$">
Header set Cache-Control "max-age=2592000"
</FilesMatch>

# disable directory browsing
Options All -Indexes

# secure htaccess file
<Files .htaccess>
 order allow,deny
 deny from all
</Files>

# secure password file
<Files .htpasswd>
 order allow,deny
 deny from all
</Files>

# secure spesific files
<Files a_secret_file.php>
 order allow,deny
 deny from all
</Files>

#SEO friendly linking
RewriteEngine On
RewriteBase /
RewriteRule ^articles/(.+)/(.+)$ index.php?page=articles&subject=$1&object=$2 [L]
RewriteRule ^articles/(.+)$ index.php?page=articles&subject=$1 [L]
RewriteRule ^labels/(.+)$ index.php?page=labels&subject=$1 [L]
RewriteRule ^(contact|labels|articles)$ index.php?page=$1 [L]

admin フォルダの .htaccess コード

AuthUserFile /path/to/public_html/.htpasswd
AuthName "Log In"
AuthType Basic
Require valid-user

RewriteEngine On
RewriteBase /
# SEO friendly linking in physical admin folder
RewriteRule ^admin/(articles|comments|questions)$ admin/index.php?adminpage=$1 [L]

adminフォルダにある.htaccessで試したコード

ノート:

  1. 管理者は物理フォルダーです
  2. /admin/... URL を除き、すべての SEO フレンドリーな URL はドメイン レベルで機能します。
  3. http://www.domain.p.ht/admin/index.php?adminpage=articles作品
  4. http://www.domain.p.ht/admin/index.php?adminpage=comments作品
  5. 物理的な管理フォルダーにある以下の.htaccessコードはすべて失敗し、404 が見つかりませんというエラーが発生しました

    RewriteRule ^admin/comments$ /admin/index.php?adminpage=$1

    RewriteRule ^admin/(articles|comments|questions)$ admin/index.php?adminpage=$1 [L]

    RewriteRule ^/admin/(articles|comments|questions)$ /admin/index.php?adminpage=$1 [L]


    訂正していただけますか?問題を解決できませんでした。また、stackoverflow の同様のタイトルの質問も検索しました。

    ブラジル

4

1 に答える 1

0

管理フォルダでこのhtaccessコードを試してください

AuthUserFile /path/to/public_html/.htpasswd
AuthName "Log In"
AuthType Basic
Require valid-user

RewriteEngine On
RewriteBase /admin/

# SEO friendly linking in physical admin folder
RewriteRule ^(articles|comments|questions)/?$ index.php?adminpage=$1 [L,QSA,NC]
于 2013-04-08T09:26:08.053 に答える