我的目标
如果输入的url分别如下:
- somedomain.p.ht/admin/articles
- somedomain.p.ht/admin/comments
预期的重写网址分别如下:
- somedomain.p.ht/admin/index.php?adminpage=articles
- somedomain.p.ht/admin/index.php?adminpage=comments
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]
管理文件夹中的 .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]
我在管理文件夹中的 .htaccess 中尝试过的代码
笔记:
- Admin 是一个物理文件夹
- 除了 /admin/... url,每个 seo 友好的 url 都在域级别工作。
http://www.domain.p.ht/admin/index.php?adminpage=articles
作品http://www.domain.p.ht/admin/index.php?adminpage=comments
作品我
.htaccess
在物理管理文件夹下面的所有代码都不成功,导致 404 not found 错误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