使用.htaccess URL重写的语法

使用.htaccess URL重写的语法,.htaccess,url-rewriting,.htaccess,Url Rewriting,我需要得到下面的URL重写语法正确,我挣扎 xxxxx.com/public_html/food/ 需要重写为: xxxxx.com/food/ 我试过这个,但不起作用: RewriteEngine On RewriteCond %{REQUEST_URI} ^/public_html/food/(.*)$ RewriteRule ^(.*)$ http://xxxxx.com/food/%1 [R=301,L] 我的客户使用的是Joomla(我不熟悉),所以我需要根据我目前研

我需要得到下面的URL重写语法正确,我挣扎

xxxxx.com/public_html/food/
需要重写为:

xxxxx.com/food/
我试过这个,但不起作用:

RewriteEngine On   
RewriteCond %{REQUEST_URI}  ^/public_html/food/(.*)$  
RewriteRule ^(.*)$ http://xxxxx.com/food/%1 [R=301,L]
我的客户使用的是Joomla(我不熟悉),所以我需要根据我目前研究的所有内容使用.htaccess文件。不过,我只是在努力让语法正常工作


谢谢

试试这个,
.htaccess

对于重写

RewriteEngine On   
RewriteRule ^food/?(.*)$ http://xxxxx.com/public_html/food/$1 [QSA,L]
对于重定向(添加R=301)

编辑:

如果要重写所有URL(包括/food)

它将允许您访问以下站点:

将指向

将指向

将指向

您是说传入的URI中有多余的
public\u html/
,您想去掉它吗?你想返回一个301状态,这样搜索引擎就会更新他们的条目,用户就会重新给它添加书签?如果您
重写规则^public_html/food/(.*)$/food/$1[R=301,L]
,会发生什么情况?
RewriteEngine On   
RewriteRule ^food/?(.*)$ http://xxxxx.com/public_html/food/$1 [R=301,QSA,L]
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public_html/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /public_html/$1 [QSA,L]