开发者

How to successfully Rewrite a URL with .htaccess

开发者 https://www.devze.com 2022-12-24 05:19 出处:网络
I am trying to rewrite mysite.com/broadcasts to mysite.com/feed so that it will show up in the location bar as \"broadcasts\" but actually go to /feed.

I am trying to rewrite mysite.com/broadcasts to mysite.com/feed so that it will show up in the location bar as "broadcasts" but actually go to /feed.

Here is what I have in the .htaccess file:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^broadcasts(/)?$ /feed/ 
</IfModule>

But this isn't working... I get a 404 error.

Wondering if I'm doin开发者_开发技巧g something stupidly wrong.

Thanks!


Here's how you do it:

RewriteRule ^(.*)/broadcasts$ $1/feed/ 

This will make sure no matter what domain you use, it will always be matched if you have the right combination, making it easier if in the future you decide to change domains for example.

UPDATE I accidentally used (.*) twice on my example, but it has been fixed

Hope this helps you


remove trailing / from /feeds/ ;-)

at least - this works for me right now


Add


RewriteRule ^broadcasts feed
in your .htaccess file. If it doesn't work, try add

RewriteEngine on
RewriteBase /
in the top of your file.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号