htaccess mod_rewrite 帮助
我有一个域名,文件夹中有一个网站。
IE http://domain.com.au/website/page.php
我只有访问 .htaccess 文件来制定规则。 我希望我的网址看起来像这样..
所以本质上我想删除它所在的子文件夹和 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..
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
1) 您可以将所有文件移动到根 Web 目录并从那里运行网站。
2) 您必须手动修改每个链接以从开头删除网站目录,然后使用 .htaccess 文件将页面重定向回适当的页面。如果您打算这样做,您不妨删除 PHP 扩展...
在某些情况下,您可能需要修改
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...
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.此 htaccess 代码将所有流量从 www.domain.com/page_one/anything/numeral 重定向
到页面 www.domain.com/webroot/products/products/view/same numeric
for your example,类似
注释,这适用于“页面” " 作为字符串,如果您需要其他函数,请更改它
以获取更多见解,您可能需要查看此链接:
http://www.javascriptkit.com/howto/htaccess.shtml
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
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