【发布时间】:2016-08-16 00:54:40
【问题描述】:
我有一个网站使用 .htaccess 重写规则,但 soem 不起作用。
这是我的 .htaccess 文件:
RewriteEngine On
RewriteBase /
# Inicio
RewriteRule ^inicio|home|index$ index.php [QSA,L]
# Paginacion amigable
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.([0-9]+)$ $1?pag=$2 [QSA,L]
# Miniaturas
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*\/)?tdd([A-Za-z0-9_~-]*)\/(.*)$ imagen.php?param=$2&src=$1$3 [QSA,L]
#paginas
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*-p([0-9]+)$ interna.php?id=$1 [QSA]
#Intranet
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*-i([0-9]+)$ intranet.php?id=$1 [QSA]
#publicaciones
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*-n([0-9]+)$ publicaciones_detalle.php?id=$1 [QSA]
# Paginas sin extension
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ $1.php [QSA]
# sitemap
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule sitemap.xml sitemap.php [QSA]
# Buscador
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^search$ buscar.php [QSA]
# En caso de no existencia
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ 404.php [QSA]
# Paginas incluidas en el template
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} ^.*\.php$
RewriteRule ^(.*)$ plantilla.php?uri=$1 [QSA]
但我有一个错误,例如当我访问 www.domain.com/contacto 它向我抛出了这个错误:
Not Found
The requested URL /contacto was not found on this server.
但如果我像这样 www.domain.com/contacto.php 更改网址,它会起作用。
我认为底部列表中的这条规则应该可以完成工作,不是吗?
# Paginas sin extension
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ $1.php [QSA]
为什么我做错了?
这些是为我的 apache 加载的所有模块:
Loaded Modules:
core_module (static)
so_module (static)
watchdog_module (static)
http_module (static)
log_config_module (static)
logio_module (static)
version_module (static)
unixd_module (static)
access_compat_module (shared)
alias_module (shared)
auth_basic_module (shared)
authn_core_module (shared)
authn_file_module (shared)
authz_core_module (shared)
authz_host_module (shared)
authz_user_module (shared)
autoindex_module (shared)
deflate_module (shared)
dir_module (shared)
env_module (shared)
filter_module (shared)
mime_module (shared)
mpm_prefork_module (shared)
negotiation_module (shared)
php7_module (shared)
rewrite_module (shared)
setenvif_module (shared)
status_module (shared)
这是我在 /etc/apache2/sites-enabled 上的 domain.dev.conf 文件:
<VirtualHost *:80>
ServerAdmin webmaster@domain.dev
DocumentRoot /var/www/html/domain/
ServerAlias www.domain.dev
ServerName domain.dev
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html/domain>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
RewriteEngine On
</Directory>
</VirtualHost>
在 apache 2.2 上运行良好,但升级到 2.4 后停止运行。
apache 2.和2.4在应用htaccess文件的形式上有区别吗
谢谢
【问题讨论】:
-
planntilla.php规则块的目的是什么?目前表明,如果您请求/foo和/foo存在并且请求文件名是/.*.php然后重写为plantilla.php- 这是没有意义的。 -
Plantilla.php 就像一个模板。所有其他页面都在该文件中回显
标签: php apache .htaccess mod-rewrite