更改网页或扩展程序中的网址

时间:2017-07-15 15:55:41

标签: php .htaccess

我有一个网站,我已将其组织在文件夹中。这是我的网站http://www.harispapadakis.eu

我想将此网址http://www.harispapadakis.eu/menu/me.php更改为http://www.harispapadakis.eu/haris

如果不可能,我会很乐意隐藏.php扩展名。我通过.htsaccess文件尝试了这个,但对我不起作用。

这是我的.htaccess文件:

<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On 
# Default directive
ExpiresDefault "access plus 1 month"
# My favicon
ExpiresByType image/x-icon "access plus 1 year"
# Images
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
# CSS
ExpiresByType text/css "access plus 1 month"
# Javascript
ExpiresByType application/javascript "access plus 1 year"
</IfModule>

ErrorDocument 404 http://www.harispapadakis.eu/404.php

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^harispapadakis.eu [nc]
rewriterule ^(.*)$ http://www.harispapadakis.eu/$1 [r=301,nc]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.html$ %{REQUEST_FILENAME}.php [L]


<IfModule mod_deflate.c>
  # Compress HTML, CSS, JavaScript, Text, XML and fonts
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE font/opentype
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/xml

  # Remove browser bugs (only needed for really old browsers)
  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
</IfModule>

1 个答案:

答案 0 :(得分:1)

您需要打开RewriteEngine,将RewriteEngine on放在.htaccess的顶部。删除.php扩展名的代码如下:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

要将/menu/me.php更改为/haris,您需要将以下行添加到.htaccess中:

RewriteRule ^haris?$ /menu/me.php [NC,L]

它应该为你做的伎俩。如果没有,请在评论中告诉我。如果我帮助点击该检查。祝你有个美好的一天。