将动态 URL 重写为友好 URL
Rewrite Dynamic URLs to Friendly URLs
我浏览了很多关于如何重写动态 URL 的不同问题,但无论出于何种原因,我都无法获得他们用来为我工作的代码。我知道我需要编辑 .htaccess 文件。
当前 URL:示例。com/search/profileview.php?storeid=1&store=aqua-addicts
理想URL:示例。com/search/profileview/aqua-addicts.html
如果这不可能,我会接受任何从 URL 中删除 ?、& 和 = 的东西。这是我目前在 .htaccess 中尝试的但不起作用的方法。
编辑:澄清不起作用
我有一个页面根据搜索条件生成结果。该页面的 link 是:
这相当于
example.com/search/profileview.php?storeid=1&store=aqua-addicts
我希望能够单击 link 并将 URL 更改为友好版本。
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+profileview\.php\?storeid=([^&]*)&.*?store=([^&\s]*) [NC]
RewriteRule ^ profileview-storeid-%1-store-%2.html? [R=302,L]
RewriteRule ^profileview-storeid-([^-]+)-store-([^.]+)\.html$ profileview.php?storeid=&store= [L,QSA,NE]
感谢任何帮助。我知道这对某些人来说可能是一个简单的改变,但我已经花了大约一天半的时间来解决这个问题。
试试这个
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^search/profileview/([^/]+).html search/profileview.php?storeid=1&store= [L]
</IfModule>
试试这个。它不会自动应用重定向,但可以让您删除不需要的 ?来自 URL.
RewriteEngine On
RewriteRule ^search/profileview/(.*).html?$ search/profileview.php?storeid=&store= [QSA,NC,L]
然后您可以调整永久链接,例如 search/profileview/aqua-addicts。html
我浏览了很多关于如何重写动态 URL 的不同问题,但无论出于何种原因,我都无法获得他们用来为我工作的代码。我知道我需要编辑 .htaccess 文件。
当前 URL:示例。com/search/profileview.php?storeid=1&store=aqua-addicts
理想URL:示例。com/search/profileview/aqua-addicts.html
如果这不可能,我会接受任何从 URL 中删除 ?、& 和 = 的东西。这是我目前在 .htaccess 中尝试的但不起作用的方法。
编辑:澄清不起作用 我有一个页面根据搜索条件生成结果。该页面的 link 是: 这相当于 example.com/search/profileview.php?storeid=1&store=aqua-addicts
我希望能够单击 link 并将 URL 更改为友好版本。
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+profileview\.php\?storeid=([^&]*)&.*?store=([^&\s]*) [NC]
RewriteRule ^ profileview-storeid-%1-store-%2.html? [R=302,L]
RewriteRule ^profileview-storeid-([^-]+)-store-([^.]+)\.html$ profileview.php?storeid=&store= [L,QSA,NE]
感谢任何帮助。我知道这对某些人来说可能是一个简单的改变,但我已经花了大约一天半的时间来解决这个问题。
试试这个
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^search/profileview/([^/]+).html search/profileview.php?storeid=1&store= [L]
</IfModule>
试试这个。它不会自动应用重定向,但可以让您删除不需要的 ?来自 URL.
RewriteEngine On
RewriteRule ^search/profileview/(.*).html?$ search/profileview.php?storeid=&store= [QSA,NC,L]
然后您可以调整永久链接,例如 search/profileview/aqua-addicts。html