使用友好的 url htaccess php 重定向用户
Redirect users with friendly urls htaccess php
我需要帮助为我的产品请求重定向和编写漂亮的 URL。
所以对于像
这样的任何请求
https://www.domain.com.au/pages/product.php?product=PRODUCTNAME
重定向并重写到
https://www.domain.com.au/pages/product/PRODUCTNAME
我实际上有:
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{SERVER_PORT} 80
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# Add trailing slash to url
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
RewriteRule ^(.*)$ / [R=301,L]
# Remove .php-extension from url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)/$ .php
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1/ [R=301,NE,L]
# End of Apache Rewrite Rules
因此它转到:
https://www.domain.com.au/pages/product/?product=PRODUCTNAME
那,对于像 about.php 等页面,这很好,您可能会意识到。
先谢谢了!
您可以使用以下方法来缩短您的产品 URL:
将以下内容放在 /root/ 的顶部。 htaccess 文件。
RewriteEngine On
#redirect /pages/product.php?product=name to /pages/product/name
RewriteCond %{THE_REQUEST} /pages/product\.php\?product=([^\s]+) [NC]
RewriteRule ^ /pages/product/%1? [L,R=301]
#Rewrite the new URL to the old one
#load the contents from the OLD URL
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^pages/product/([^/]+)/?$ /pages/product.php?product= [L]
我需要帮助为我的产品请求重定向和编写漂亮的 URL。
所以对于像
这样的任何请求https://www.domain.com.au/pages/product.php?product=PRODUCTNAME
重定向并重写到
https://www.domain.com.au/pages/product/PRODUCTNAME
我实际上有:
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{SERVER_PORT} 80
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# Add trailing slash to url
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
RewriteRule ^(.*)$ / [R=301,L]
# Remove .php-extension from url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)/$ .php
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1/ [R=301,NE,L]
# End of Apache Rewrite Rules
因此它转到: https://www.domain.com.au/pages/product/?product=PRODUCTNAME
那,对于像 about.php 等页面,这很好,您可能会意识到。 先谢谢了!
您可以使用以下方法来缩短您的产品 URL:
将以下内容放在 /root/ 的顶部。 htaccess 文件。
RewriteEngine On
#redirect /pages/product.php?product=name to /pages/product/name
RewriteCond %{THE_REQUEST} /pages/product\.php\?product=([^\s]+) [NC]
RewriteRule ^ /pages/product/%1? [L,R=301]
#Rewrite the new URL to the old one
#load the contents from the OLD URL
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^pages/product/([^/]+)/?$ /pages/product.php?product= [L]