简体   繁体   English

我如何htaccess重定向和重写index.php和参数到新的url,而无需更改链接或文件?

[英]How do I htaccess redirect and rewrite index.php & parameters to new url, without changing links or files?

If I have a website with url of 如果我的网站网址为

/index.php?view=prod&id=11

(where 11 can be any id number) (其中11可以是任何ID号)

How do I redirect and rewrite this to an SEF link like 如何将其重定向重写为SEF链接,例如

/product/11/

So that anyone that goes to the index.php... link will always get redirected to the SEF link? 这样,转到index.php ...链接的任何人都将始终重定向到SEF链接吗?

My solution so far is 到目前为止,我的解决方案是

RewriteRule    ^product/([0-9]+)/?$    index.php?view=prod&id=$1 [NC,L] 

But that doesn't redirect the original index.php link at all, and though the SEF link works for some reason it doesn't display any CSS.... which is weird. 但这根本不会重定向原始的index.php链接,尽管SEF链接由于某种原因起作用,但它不显示任何CSS...。这很奇怪。

Thanks. 谢谢。

For the .htaccess , use: 对于.htaccess ,请使用:

Options -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} \s/+index\.php\?view=prod&id=([^\s&]+) [NC]
RewriteRule ^ /product/%1/? [R=302,L,NE]

RewriteRule ^product/(\d+)/?$ index.php?view=prod&id=$1 [NC,L]

Change [R=302] for [R=301] when test work well. 测试工作正常时,将[R=301] [R=302]更改为。

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

相关问题 htaccess 重写 index.php 如果没有 www 则重定向 - htaccess rewrite index.php and redirect if without www 我如何htaccess将index.html重定向到index.php并将index.php重定向到/ - How do I htaccess redirect index.html to index.php and index.php to / HTACCESS REWRITE:忽略语言代码并将index.php添加到url而不更改它 - HTACCESS REWRITE: Ignore Language code and add index.php to the url without changing it 如何在不使用301重定向的情况下使用htaccess将所有子域路由到index.php - How do I route all subdomains to index.php using htaccess without 301 redirect .htaccess:从公共目录提供静态文件,而没有URL中的公共文件,否则重写为index.php - .htaccess: Serve static files from public directory without public in URL, else rewrite to index.php htaccess将带有扩展名的旧index.php重定向到新的url - htaccess redirect old index.php with extensions to new url .htaccess在没有index.php的情况下重写 - .htaccess Rewrite without index.php .htaccess index.php网址重定向 - .htaccess index.php url redirect .htaccess URL重写如何在URL中包含index.php? - How to do .htaccess URL rewriting to include index.php in the URL? 如何重写此.htaccess文件,以从CodeIgniter中删除index.php并强制使用HTTPS? - How do I rewrite this .htaccess file to remove index.php from CodeIgniter and force HTTPS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM