php - htaccess 重写本地主机的更改

标签 php apache .htaccess mod-rewrite

我一直在尝试让该网站在我的本地计算机上运行,​​但由于 .htaccess 文件设置我一直未能成功尝试更改,因此链接不再有效。页面内容位于数据库中,链接如下所示

<a href="<?=$linkLocations?>" id="bestLoc"<?=$activeBest?>>Best Locations</a>

该变量被定义为全局变量

$linkLocations = $URL . '/best-locations';

而 bestLocations 实际上是一个查询数据库的 .php 文件。 .htaccess 文件显示了很多重写规则,这是完整的文件

# compress text, html, javascript, css, 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



ExpiresActive On

ExpiresByType image/gif A2592000

ExpiresByType image/jpeg A2592000

ExpiresByType image/jpg A2592000

ExpiresByType image/png A2592000

ExpiresByType image/x-icon A2592000

ExpiresByType text/css A604800

ExpiresByType application/javascript A604800

ExpiresByType application/x-shockwave-flash A2592000

<FilesMatch "\.(gif¦jpe?g¦png¦ico¦css¦js¦swf)$">

Header set Cache-Control "public"

</FilesMatch>



RewriteEngine on
fafaf


RewriteCond %{HTTP_HOST} !^$

RewriteCond %{HTTP_HOST} !^www\. [NC]

RewriteCond %{HTTPS}s ^on(s)|

RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]



RewriteRule ^communities/([a-zA-Z0-9\_\-]+)$ communities/index.php?community=$1 [NC]

RewriteRule ^communities/([a-zA-Z0-9\_\-]+)/$ communities/index.php?community=$1 [NC]



RewriteRule ^communities/([a-zA-Z0-9\_\-]+)/([a-zA-Z0-9\_\-]+)$ communities/index.php?community=$1&commPage=$2 [NC]

RewriteRule ^communities/([a-zA-Z0-9\_\-]+)/([a-zA-Z0-9\_\-]+)/$ communities/index.php?community=$1&commPage=$2 [NC]



RewriteRule ^communities/([a-zA-Z0-9\_\-]+)/([a-zA-Z0-9\_\-]+)/([a-zA-Z0-9\_\-]+)$ communities/index.php?community=$1&commPage=$2&model=$3 [NC]

RewriteRule ^communities/([a-zA-Z0-9\_\-]+)/([a-zA-Z0-9\_\-]+)/([a-zA-Z0-9\_\-]+)/$ communities/index.php?community=$1&commPage=$2&model=$3 [NC]



RewriteRule ^([a-zA-Z0-9\_\-]+)$ subpage.php?page=$1 [NC]

RewriteRule ^([a-zA-Z0-9\_\-]+)/$ subpage.php?page=$1 [NC]



RewriteRule ^([a-zA-Z0-9\_\-]+)/([a-zA-Z0-9\_\-]+)$ subpage.php?page=$1&sp=$2 [NC]

RewriteRule ^([a-zA-Z0-9\_\-]+)/([a-zA-Z0-9\_\-]+)/$ subpage.php?page=$1&sp=$2 [NC]



RewriteRule ^([a-zA-Z0-9\_\-]+)/([a-zA-Z0-9\_\-]+)/([a-zA-Z0-9\_\-]+)$ subpage.php?page=$1&sp=$2&spd=$3 [NC]

RewriteRule ^([a-zA-Z0-9\_\-]+)/([a-zA-Z0-9\_\-]+)/([a-zA-Z0-9\_\-]+)/$ subpage.php?page=$1&sp=$2&spd=$3 [NC]
  • 我没有更改实时版本的重写内容。
  • 我正在通过 localhost/bentley/通过 WAMP 访问 URL
  • 实时站点是 http://bentleyhomes.com
  • 网站的目录结构没有链接页面, 而是输出数据库数据的 php 文件

我知道我在这里遗漏了很多东西,而且可能超出了我的深度,但如果有人能指出我的大致方向,我将不胜感激;我花了一个上午的时间学习 htaccess 教程,但这对我来说仍然有点困难。

最佳答案

尝试:

RewriteEngine on
RewriteRule ^([a-zA-Z0-9\_\-]+)$ subpage.php?page=$1 [NC,L]

现在(编辑后),没有:

fafaf
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

关于php - htaccess 重写本地主机的更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33246556/

相关文章:

php - getJSON - 为什么它不起作用?

php - 本地主机,子域,使用 XAMPP

php - Netbeans PHP 项目 Apache 设置 -

apache - 使用Hadoop 2.4.1时Oozie 4.0.1构建错误

php - .htaccess 文件是否在本地主机上工作?如果是如何?

php - 通用 MySQL 全选函数

java - Apache Jackrabbit 中的临时文件不会被删除

java - 如何让客户端使用新的java小程序加载新的html页面

php - .htaccess 未从网址中删除 .php 扩展名

.htaccess - htaccess 在不重定向的情况下加载页面 B 而不是页面 A