简体   繁体   English

具有2个网址.htaccess的同一页面无重定向

[英]Same page with 2 urls .htaccess no redirect

I have a page where i am listing all my products. 我有一个页面,其中列出了我所有的产品。 But i want the same page on different url also. 但我也想在不同的网址上的同一页。 So the both urls should open same page with any redirect. 因此,这两个网址均应使用任何重定向打开同一页面。

Original URL is: http://example.com/product/all-products New URL with same content should be http://example.com/all-products 原始URL为: http://example.com/product/all-products : http://example.com/product/all-products具有相同内容的新URL应该为http://example.com/all-products

How can i do that with .htaccess? .htaccess该怎么办?

Try the below rule 尝试以下规则

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([\w-]+)$ product/$1 [L]

You can use the following in /root.htaccess : 您可以在/root.htaccess中使用以下命令

RewriteEngine on
#1 redirect browser url from "/product/foobar" to "/foobar"
RewriteCond %{THE_REQUEST} /product/(.+)\sHTTP [NC]
RewriteRule ^ /%1 [L,R,NE]
#2 if "/foobar" exists as a file or dir in product folder
RewriteCond %{DOCUMENT_ROOT}/product/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/product/$1 -d
#3 then rewrite "/foobar" to "/product/foobar"
RewriteRule ^(.*?)/?$ /product/$1 [L]

If the example above fails, you could try the following 如果以上示例失败,则可以尝试以下操作

RewriteEngine on

RewriteCond %{THE_REQUEST} /product/(.+)\sHTTP [NC]
RewriteRule ^ /%1 [L,R,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /product/$1 [L]

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

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