我试图创建一个简单的htaccess文件来执行以下操作:
这是我到目前为止所做的,但它似乎并没有起作用:
IndexIgnore .htaccess
DirectoryIndex index.php
Options -Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^([^/.]+)/?$ $1.php
RewriteRule page1/(.*)/$ /page1?u=$1
RewriteRule page1/(.*)$ /page1?u=$1
RewriteRule page2/(.*)/$ /page2?t=$1
RewriteRule page2/(.*)$ /page2?t=$1
ErrorDocument 400 http://www.domain.com/error?e=400
ErrorDocument 401 http://www.domain.com/error?e=401
ErrorDocument 403 http://www.domain.com/error?e=403
ErrorDocument 404 http://www.domain.com/error?e=404
ErrorDocument 500 http://www.domain.com/error?e=500
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
任何帮助都将不胜感激,谢谢。
答案 0 :(得分:1)
试试这个:
IndexIgnore .htaccess
DirectoryIndex index.php
Options -Indexes
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http://www.%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L]
#Remove .php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^.]+)/?$ /$1.php [L,NC]
RewriteCond %{THE_REQUEST} /page\?u=([^\s]+)
RewriteRule ^ /page/%1? [NE,R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ /page?u=$2 [L,NC]