【问题标题】:.htaccess file not able to rename subfolder instead getting page not found.htaccess 文件无法重命名子文件夹,而是找不到页面
【发布时间】:2015-06-25 09:49:27
【问题描述】:

我在 google 甚至在 stackoverflow.com 上也进行了很多搜索。我发现了一些很好的问题和他们的答案,但不幸的是没有答案对我有用。我编写了一个 cms 类型的 Web 应用程序,其中公共访问文件位于根目录中,而控制面板文件位于 admin 文件夹中。现在我希望所有控制面板文件都应该使用http://www.example.com/administrator url 运行,为此我编写了这个 .httacess 文件。

.htaccess

# BEGIN     
<IfModule mod_rewrite.c>

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

RewriteRule ^single _single_Page.php [NC,L]
RewriteRule ^single/([A-Za-z0-9-]+)/?$ _single_Page.php?subid=$1 [NC,L]
RewriteRule ^findcontents$ _findContentTitle.php [L,QSA]
#RewriteRule ^findcontents/([A-Za-z0-9-]+)/?$ _findContentTitle.php?data=$1 [L,QSA]
RewriteRule ^search$ _specificPage.php [NC,L] [L,QSA]




# Admin panel redirect settings

RewriteRule ^/administrator(.*)?$ /admin$1 [NC]


RewriteRule ^authenticate _checkaccess.php [NC,L]

</IfModule>

# END 

从根文件工作正常,但是当我尝试 www.example.com/administrator 时。我收到页面未找到错误。请有人帮助我。我在 .htaccess 文件中弄错了什么。

我一直在使用 rewrite a folder name using .htaccess 重命名文件夹

我也试过这段代码

RewriteCond %{REQUEST_URI} ^/administrator/(.*)$
RewriteCond %{DOCUMENT_ROOT}/admin/%1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/admin/%1 -d
RewriteRule ^ /admin/%1 [L]

但我仍然收到页面​​未找到错误。只是为了了解我正在使用 godaddy 托管。上面的示例适用于本地主机。但不适用于 Godaddy 托管。

【问题讨论】:

  • 这两个管理规则目前并没有真正做任何事情。第一个将重写为第二个,第二个将重写回第一个。使用example.com/administrator 时,您想获得什么实际的页面
  • 我尝试了第二个,但它不起作用。好的,我将删除第一个。

标签: php regex apache .htaccess mod-rewrite


【解决方案1】:

在您的根 .htaccess 中尝试这些规则:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

RewriteRule ^administrator(.*)$ /admin$1 [NC,L]
RewriteRule ^authenticate _checkaccess.php [NC,L]
RewriteRule ^single _single_Page.php [NC,L]
RewriteRule ^single/([A-Za-z0-9-]+)/?$ _single_Page.php?subid=$1 [NC,L]
RewriteRule ^findcontents$ _findContentTitle.php [L,QSA]
#RewriteRule ^findcontents/([A-Za-z0-9-]+)/?$ _findContentTitle.php?data=$1 [L,QSA]
RewriteRule ^search$ _specificPage.php [NC,L] [L,QSA]

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

【讨论】:

  • 请告诉我我在 .htaccess 文件中犯了什么错误。它与我的接缝相似,但工作正常。
  • 您的 RewriteRule 中有一个前导斜杠,并且规则的顺序不正确。
  • 好吧,意思是order metter没错。感谢好友的宝贵帮助和支持。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-03
  • 1970-01-01
  • 1970-01-01
  • 2014-02-28
相关资源
最近更新 更多