如果输入网址分别如下所示:
预期的重写网址分别如下:
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]
管理员文件夹中的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]
注意:
http://www.domain.p.ht/admin/index.php?adminpage=articles
正常工作http://www.domain.p.ht/admin/index.php?adminpage=comments
正常工作我在物理管理员文件夹中的.htaccess
以下所有代码均为unsuccesfull,导致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的类似标题问题。
BR
答案 0 :(得分:0)
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]