htaccess mod_rewrite 帮助

发布于 2024-08-23 13:42:15 字数 554 浏览 2 评论 0原文

我有一个域名,文件夹中有一个网站。

IE http://domain.com.au/website/page.php

我只有访问 .htaccess 文件来制定规则。 我希望我的网址看起来像这样..

http://domain.com.au/page

所以本质上我想删除它所在的子文件夹和 php 扩展名。

我的 php 中的所有链接都是这样构造的,尽管

<a href="/website/page.php">page link</a>

js 和 css 是相同的。它们都是从“网站”文件夹中引用的。

重写是否意味着我必须更改所有链接?

优先事项是从 url 中删除文件夹,而不是 php 扩展。

i have a domain with a website in a folder.

i.e
http://domain.com.au/website/page.php

i only have access to .htaccess files to make the rules.
i would like my url to look like this..

http://domain.com.au/page

so in essence i want to drop the subfolder its sitting in, and the php extention.

All links in my php are structured like this though

<a href="/website/page.php">page link</a>

this is the same for js and css. they are all referenced from the 'website' folder.

will the rewrite mean i have to change all my links?

priority is dropping the folder from the url, not so much the php extension.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怀中猫帐中妖 2024-08-30 13:42:15

1) 您可以将所有文件移动到根 Web 目录并从那里运行网站。
2) 您必须手动修改每个链接以从开头删除网站目录,然后使用 .htaccess 文件将页面重定向回适当的页面。如果您打算这样做,您不妨删除 PHP 扩展...

RewriteEngine On
Options +FollowSymLinks

RewriteCond %{HTTP_HOST} ^domain.com.au$ [NC]
RewriteRule ^(.*)/ website/$1.php [L]

在某些情况下,您可能需要修改 website/$1.php 部分以包含整个根目录,但只要 .htaccess 文件位于 Web 根目录中,就应该可以工作。这会将“http://domain.com.au/page”形式的任何页面重定向到'http://domain.com.au/website/page.php' 而保持地址栏中的 URL 相同。

1) You could move all the files to the root web directory and run the website from there.
2) You would have to manually modify every link to remove the website directory from the beginning and then use the .htaccess file to redirect the pages back to the appropriate page. If you're going to do it this way, you might as well remove the PHP extension...

RewriteEngine On
Options +FollowSymLinks

RewriteCond %{HTTP_HOST} ^domain.com.au$ [NC]
RewriteRule ^(.*)/ website/$1.php [L]

You may have to modify the website/$1.php part to include your entire root directory in some cases, but that should work as long as the .htaccess file is in the root web directory. That will redirect any page in the form 'http://domain.com.au/page' to 'http://domain.com.au/website/page.php' while keeping the URL the same in the address bar.

┈┾☆殇 2024-08-30 13:42:15
<IfModule mod_rewrite.c>
    RewriteEngine on

        RewriteRule    ^page\_one/(.*)/([0-9]{1,6})/?$ webroot/products/products/view/$2    [L]

 </IfModule>

此 htaccess 代码将所有流量从 www.domain.com/page_one/anything/numeral 重定向

到页面 www.domain.com/webroot/products/products/view/same numeric

for your example,类似

    RewriteRule    ^page?$ website/page.php$2    [L]

注释,这适用于“页面” " 作为字符串,如果您需要其他函数,请更改它

以获取更多见解,您可能需要查看此链接:
http://www.javascriptkit.com/howto/htaccess.shtml

<IfModule mod_rewrite.c>
    RewriteEngine on

        RewriteRule    ^page\_one/(.*)/([0-9]{1,6})/?$ webroot/products/products/view/$2    [L]

 </IfModule>

this htaccess code redirects all trafic from www.domain.com/page_one/anything/numeral

to the page www.domain.com/webroot/products/products/view/same numeral

for your example, something like

    RewriteRule    ^page?$ website/page.php$2    [L]

note, this works for "page" as a string, if you need other functions , change it

for more insight, you might want to take a look at this link :
http://www.javascriptkit.com/howto/htaccess.shtml

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文