Php 使用url变量重写mod_

Php 使用url变量重写mod_,php,regex,apache,.htaccess,mod-rewrite,Php,Regex,Apache,.htaccess,Mod Rewrite,我正在尝试转换以下内容: 至(无扩展) 或 to(使用.php扩展名) 我已经编写了删除url扩展的代码,但我似乎无法解决这个问题 我尝试了以下方法: RewriteRule^gallery/([^/]+)/?$gallery.php?页面=$1 RewriteRule^gallery/page/([0-9])[/]?$gallery.php?page=$1 重写规则^gallery/page/([0-9])[/]?$gallery?page=$1 RewriteRule^gallery/(

我正在尝试转换以下内容:

至(无扩展)

to(使用
.php
扩展名)

我已经编写了删除url扩展的代码,但我似乎无法解决这个问题

我尝试了以下方法:

RewriteRule^gallery/([^/]+)/?$gallery.php?页面=$1
RewriteRule^gallery/page/([0-9])[/]?$gallery.php?page=$1
重写规则^gallery/page/([0-9])[/]?$gallery?page=$1
RewriteRule^gallery/([0-9]+)/?$gallery.php?页面=$1[NC]
重写规则^gallery/([0-9]+)/?$gallery?页面=$1[NC,L]
这些都不起作用

我已经读到
L
告诉脚本停止,如果它工作,我是否需要从
L
中删除
L
,除了
.htaccess
文件中的最后一行之外的所有内容

这是我目前的完整
.htaccess

重新编写引擎打开
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则(.*)$1.php[L]
重写cond%{THE_REQUEST}^[A-Z]{3,}\s(.*?/+)index\.php(?:/(.*)?[\s?][NC]
重写规则^1%2[L,R]
#在内部将index.php添加到所有URI
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^index\.php index\.php%{REQUEST_URI}[L,NC]
重写cond%{u请求}^[A-Z]{3,}\s(.*?/+)索引(?:/(.*))?[\s?][NC]
重写规则^1%2[L,R]
#在内部向所有URI添加索引
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^索引%{REQUEST_URI}[L,NC]
重写规则^gallery/([0-9]+)/?$gallery.php?页面=$1[NC]#处理gallery请求
重写规则^gallery/([0-9]+)/?$gallery?页面=$1[NC,L]#处理gallery请求
ErrorDocument 400/error.php
ErrorDocument 401/error.php
ErrorDocument 403/error.php
ErrorDocument 404/error.php
ErrorDocument 500/error.php
ErrorDocument 502/error.php
ErrorDocument 504/error.php
试试:

RewriteEngine On
RewriteCond %{THE_REQUEST} /gallery\.php\?page=([^\s]+) [NC] 
RewriteRule ^ gallery/%1? [NC,R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^gallery/([^/]+)/?$ gallery.php?page=$1 [QSA,L,NC]

这应该是您的完整访问权限。htaccess:

ErrorDocument 400 /error.php
ErrorDocument 401 /error.php
ErrorDocument 403 /error.php
ErrorDocument 404 /error.php
ErrorDocument 500 /error.php
ErrorDocument 502 /error.php
ErrorDocument 504 /error.php

Options -MultiViews
RewriteEngine On
RewriteBase /

# To externally redirect /dir/file.php to /dir/file
RewriteCond %{THE_REQUEST} /gallery\.php\?page=([^&\s]+) [NC] 
RewriteRule ^ /gallery/%1? [R=302,L]

RewriteCond %{THE_REQUEST} \s/+(.*?/)?(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ /%1%2 [R=302,L,NE]

# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

# To internally forward /dir/file to /dir/file.php
RewriteRule ^gallery/([^/]+)/?$ gallery.php?page=$1 [QSA,L,NC]

RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]

RewriteRule !^index\.php/ index\.php%{REQUEST_URI} [L,NC]
  • 规则的排序在htaccess中很重要
  • 多视图
    需要关闭
  • index.php
    规则应该是最后一个规则,因为该规则正在处理所有非文件/非目录

  • 500内部服务器错误,我找不到错误日志。我正在使用Godaddy作为主机。可能是