URL重写-.htaccess [英] URL Rewrite -.htaccess

查看:109
本文介绍了URL重写-.htaccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简单的URL重写从链接删除的扩展名为.php 我现在用的是下面的code上的.htaccess文件

Simple URL Rewriting for removing .php extensions from the links I am using the following code on the .htaccess file

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php[\s?] [NC]
RewriteRule ^ %1 [R=301,L]

# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ /$1.php [L]

上传网站的托管服务器上的上述mod_rewrite的code导致的页面下面的链接,因为我需要经过...

After uploading the site on the hosting server the above mod_rewrite code lead the pages to the following links as I needed...

domain.com/abc/index
domain.com/abc/about
domain.com/abc/services
domain.com/abc/rates
domain.com/abc/contact#main

但显示的(404页未找到错误)这些页面即不显示精确的页面类似的index.php,about.php,services.php,rates.php和contact.php#主....等

but showing (404 Page Not Found ERROR) for these pages i.e Not showing the exact pages like index.php, about.php, services.php, rates.php and contact.php#main.... etc

任何人都可以请让我知道我缺少的是什么?由于网页上的像

Can anybody please let me know what I am missing? As the Menu links on the web pages like

< UL类=导航> <李>< A HREF =的index.php>首页< / A>< /李> <李>< A HREF =about.php>关于< / A>< /李> <李>< A HREF =services.php>服务< / A>< /李> <李>< A HREF =rates.php>价格和LT; / A>< /李> <李>< A HREF =contact.php#主>联系我们< / A>< /李> < / UL>

<ul class="nav"> <li><a href="index.php">Home</a></li> <li><a href="about.php">About</a></li> <li><a href="services.php">Services</a></li> <li><a href="rates.php">Rates</a></li> <li><a href="contact.php#main">Contact Us</a></li> </ul>

我应该要做些什么这些菜单链接吗?

Should I have to do something with these menu links too?

推荐答案

这将您的的.php 文件:

public_html/*.php

要:

public_html/gta/*.php

会发生什么事是你正在访问:

What happens is that you're accessing:

http://domain.com/gta/about

和它试图找到的.php 文件:

http://domain.com/gta/about.php

但是,从你告诉我的文件都在previous文件夹,所以它是唯一正确的,它会给你一个404错误。

But from what you told me the files are on the previous folder so it's only right it will give you a 404 error.

由于所有的文件都在文件夹多伦多的.htaccess 可以是你到底有没有,但需求要对的public_html 文件夹并应无的.htaccess GTA 文件夹

Given that all files are on the folder gta you .htaccess can be what you exactly have, but needs to be on the public_html folder and there should be NO .htaccess inside the gta folder:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php[\s?] [NC]
RewriteRule ^ %1 [R=301,L]

# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ /$1.php [L]

这篇关于URL重写-.htaccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆