简体   繁体   English

htaccess mod_rewrite帮助

[英]htaccess mod_rewrite help

i have a domain with a website in a folder. 我有一个文件夹中有一个网站的域。

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

i only have access to .htaccess files to make the rules. 我只能访问.htaccess文件来制定规则。 i would like my url to look like this.. 我希望我的网址看起来像这样。

http://domain.com.au/page http://domain.com.au/page

so in essence i want to drop the subfolder its sitting in, and the php extention. 因此,从本质上讲,我想将子文件夹放置在其中,并放下php扩展名。

All links in my php are structured like this though 我的PHP中的所有链接都是这样的结构

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

this is the same for js and css. js和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. 优先是从url删除文件夹,而不是从php扩展名删除。

1) You could move all the files to the root web directory and run the website from there. 1)您可以将所有文件移动到根Web目录,然后从那里运行网站。 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. 2)您必须手动修改每个链接,才能从头开始删除网站目录,然后使用.htaccess文件将页面重定向回相应的页面。 If you're going to do it this way, you might as well remove the PHP extension... 如果您要这样做,则最好删除PHP扩展...

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

<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 此htaccess代码会将所有流量重定向到www.domain.com/page_one/anything/numeral

to the page www.domain.com/webroot/products/products/view/same numeral 到页面www.domain.com/webroot/products/products/view/相同的数字

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 要获取更多信息,您可能需要查看以下链接: http : //www.javascriptkit.com/howto/htaccess.shtml

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM