.htaccess rewrite url for cms news

Status
Not open for further replies.

SaW

Member
Mar 3, 2018
101
15
Trying to rewrite the url of my news section, but doesn't work on server, neither on localhost.
I want to change the url from to something more simpler like , and have put this rule into my .htaccess:
Code:
RewriteRule ^news/([0-9]+)$    /index.php?url=news&id=$1
.. but still doesn't work.

Any help would be appreciated, thx.
 

JayC

Always Learning
Aug 8, 2013
5,504
1,401
Do you have IIS, or XAMPP?
 
IIS:

Code:
<rule name="News">
     <match url="^news/([a-zA-Z0-9_-]+)(|/)$" ignoreCase="false" />
     <action type="Rewrite" url="index.php?url=news&amp;id={R:1}" appendQueryString="false" />
</rule>
 

JayC

Always Learning
Aug 8, 2013
5,504
1,401
Trying on both IIS and local on XAMPP. I'm bit of a noob, where do i put this?
Well, First of all if you are using XAMPP on your local , you would add that rule you created in your .htaccess

IIS does not read .htaccess, it reads web.config.

You should put this in your web.config file on your server under the <rules> </rules> tags in its own spot.

Then restart your IIS service to reload your website rules immediately.
 

SaW

Member
Mar 3, 2018
101
15
Well, First of all if you are using XAMPP on your local , you would add that rule you created in your .htaccess

IIS does not read .htaccess, it reads web.config.

You should put this in your web.config file on your server under the <rules> </rules> tags in its own spot.

Then restart your IIS service to reload your website rules immediately.

You must be registered for see images attach

Still haven't changed after adding rule and restarting IIS
 

JayC

Always Learning
Aug 8, 2013
5,504
1,401
I think you are confused what rules do in the first place bud.

Rules aren't going to change the links in your website automatically. If you load index.php?url=news it will load index.php?url=news

The purpose of rules are to act like interfaces, protecting where your data is coming from, but also to clean up your URL so its not a long string of things. Instead of having

index.php?page=news&id=1&rank=4&username=JayCustom&hidden_values=2

You could shorten that by having a rule that will take THIS URL:
/news/1/4/JayCustom/2

and convert it behind the scenes, and bring the information of the long URL back to the shortened one.

Long story short,
After adding the rules, if you manually type in the URL bar /news/1
It will load the first news article.

It will not update the links on your site
 
  • Like
Reactions: SaW

SaW

Member
Mar 3, 2018
101
15
Holy shit, i see now, thank you very much! Then everything works as it should, just gotta change the links to my news section.
 
  • Like
Reactions: Joe
Status
Not open for further replies.

Users who are viewing this thread

Top