如何为基于IP的服务器编写.htaccess代码

时间:2014-08-19 09:23:08

标签: php .htaccess mod-rewrite rewrite

我的网站网址是182.231.82.182/~globalme/testing /

此处测试是我的网站文件夹。当我尝试写入.htacces文件时,我收到此错误:

  

500内部服务器错误

     

请求未完成。服务器遇到了意外情况。

     

182.231.82.182/~globalme/testing/home.php(80端口)

     

请将此错误屏幕转发至182.231.82.182的WebMaster。

我的.htacces文件是:

ErrorDocument 404 /404.php
ErrorDocument 403 /403.php

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$
RewriteCond %{HTTP_HOST} ^182.231.82.182/~globalme/testing/ [NC]
RewriteRule ^(.*)$ http://182.231.82.182/~globalme/testing/$1 [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://182.231.82.182/~globalme/testing/ [R=301,L]

AddType application/x-httpd-php .htm .html
AddHandler x-httpd-php  .htm .html

RewriteRule ^(.*)\.html$ $1\.php [nc]
RewriteCond %{REQUEST_URI} !home\.php  [NC]
RewriteRule (.*)/home\.html$ /home.php?city=$1

#RewriteCond %{REQUEST_URI} !hospital-list\.php  [NC]
RewriteRule (.*)/hospital\.html$ /hospital-list.php?city=$1
RewriteRule (.*)/(.*)/hospital\.php$ /hospital-list.php?city=$1&menutype=$2

#RewriteCond %{REQUEST_URI} !doctor-list\.php  [NC]
RewriteRule (.*)/doctor\.html$ /doctor-list.php?city=$1
RewriteRule (.*)/(.*)/doctor\.php$ /doctor-list.php?city=$1&menutype=$2

#RewriteCond %{REQUEST_URI} !pharmacy-list\.php  [NC]
RewriteRule (.*)/pharmacy\.html$ /pharmacy-list.php?city=$1

RewriteCond %{REQUEST_URI} !bloodbank-list\.php  [NC]
RewriteRule (.*)/bloodbank\.html$ /bloodbank-list.php?city=$1

RewriteCond %{REQUEST_URI} !ambulance-list\.php  [NC]
RewriteRule (.*)/ambulance\.html$ /ambulance-list.php?city=$1

RewriteCond %{REQUEST_URI} !fitnesscenter-list\.php  [NC]
RewriteRule (.*)/fitnesscenter\.html$ /fitnesscenter-list.php?city=$1

#RewriteCond %{REQUEST_URI} !article-list\.php  [NC]
RewriteRule article\.php$ /article-list.php
#RewriteRule (.*)/article\.html$ /article-list.php

RewriteCond %{REQUEST_URI} !contactus\.php  [NC]
RewriteRule contactus\.html$ /contactus.php
#RewriteRule (.*)/contactus\.html$ /contactus.php?city=$1

RewriteCond %{REQUEST_URI} !article-view\.php  [NC]
RewriteRule article/(.*)-(.*)\.html$ /article-view.php?name=&1&id=$2
#RewriteRule (.*)/article/(.*)-(.*)\.html$ /article-view.php?city=$1&name=&2&id=$3

RewriteCond %{REQUEST_URI} !hospital-view\.php  [NC]
RewriteRule (.*)/hospital/(.*)-(.*)\.html$ /hospital-view.php?city=$1&name=&2&id=$3

RewriteCond %{REQUEST_URI} !doctor-view\.php  [NC]
RewriteRule (.*)/doctor/Dr.(.*)-(.*)\.html$ /doctor-view.php?city=$1&name=&2&id=$3

RewriteCond %{REQUEST_URI} !pharmacy-view\.php  [NC]
RewriteRule (.*)/pharmacy/(.*)-(.*)\.html$ /pharmacy-view.php?city=$1&name=&2&id=$3

RewriteCond %{REQUEST_URI} !bloodbank-view\.php  [NC]
RewriteRule (.*)/bloodbank/(.*)-(.*)\.html$ /bloodbank-view.php?city=$1&name=&2&id=$3

RewriteCond %{REQUEST_URI} !ambulance-view\.php  [NC]
RewriteRule (.*)/ambulance/(.*)-(.*)\.html$ /ambulance-view.php?city=$1&name=&2&id=$3

RewriteCond %{REQUEST_URI} !fitnesscenter-view\.php  [NC]
RewriteRule (.*)/fitnesscenter/(.*)-(.*)\.html$ /fitnesscenter-view.php?city=$1&name=&2&id=$3

RewriteCond %{REQUEST_URI} !medical-info-videos\.php  [NC]
RewriteRule medicalinfovideos/(.*)\.php$ /medical-info-videos.php?id=$1
#RewriteRule (.*)/medicalinfovideos/(.*)\.html$ /medical-info-videos.php?city=$1&id=$2

RewriteCond %{REQUEST_URI} !health-tips\.php  [NC]
RewriteRule health-tips\.html$ /health-tips.php

RewriteCond %{REQUEST_URI} !awareness-days\.php  [NC]
RewriteRule awareness-days\.html$ /awareness-days.php

RewriteCond %{REQUEST_URI} !feedback\.php  [NC]
RewriteRule feedback\.html$ /feedback.php
#RewriteRule (.*)/feedback\.html$ /feedback.php?city=$1

RewriteCond %{REQUEST_URI} !sitemap\.php  [NC]
RewriteRule sitemap\.html$ /sitemap.php

RewriteCond %{REQUEST_URI} !privacy-policy\.php  [NC]
RewriteRule privacy-policy\.html$ /privacy-policy.php
#RewriteRule (.*)/privacy-policy\.html$ /privacy-policy.php?city=$1

RewriteCond %{REQUEST_URI} !add-detail\.php  [NC]
RewriteRule add-detail\.html$ /add-detail.php
#RewriteRule (.*)/add-detail\.html$ /add-detail.php?city=$1

RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
#RewriteRule ^(.*)-hospital-details([0-9]+).htm$ /Chennai/hospital.html


# compress text, HTML, JavaScript, CSS, and 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
AddOutputFilterByType DEFLATE text/javascript

AddOutputFilter DEFLATE js css
AddOutputFilterByType DEFLATE text/plain text/xml application/xhtml+xml text/css application/xml application/rss+xml application/atom_xml application/x-javascript application/x-httpd-php application/x-httpd-fastphp text/html

# remove browser bugs
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent

## EXPIRES CACHING ##

ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/pdf "access plus 1 year"
ExpiresByType text/x-javascript "access plus 1 year"
ExpiresByType application/x-shockwave-flash "access plus 1 year"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 year"

## EXPIRES CACHING ##

<IfModule mod_headers.c>
  <FilesMatch "\.(js|css|xml|gz)$">
    Header append Vary: Accept-Encoding
  </FilesMatch>
</IfModule>

0 个答案:

没有答案