.ht file

Status
Not open for further replies.

ziycon

New Member
Below is what i have in my .ht file, the first rewrite works fine but the second wont work at all!, am i missing something?
Code:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /

RewriteRule ^news-([^/]*)\.htm$ /news.php?page=$1 [L]
RewriteRule ^news-topic-([^/]*)\.htm$ /news_topic.php?topic=$1 [L]
 

louie

New Member
try adding NC as well after the L
Code:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
 
#move this first
RewriteRule ^news-topic-(.*)\.(htm|html|php)$ /news_topic.php?topic=$1 [L,NC]
#above as it starts with the same ^news-
 
RewriteRule ^news-([^/]*)\.(htm|html|php)$ /news.php?page=$1 [L,NC]
#what do you expect here: -([^/]*) - numbers or letters?
#if number you can try this: -([0-9]+)

the start should be unique for better reference to what you want

I will start the first one with "topic-news" and second to just "news"
 

ziycon

New Member
try adding NC as well after the L
Code:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
 
#move this first
RewriteRule ^news-topic-(.*)\.(htm|html|php)$ /news_topic.php?topic=$1 [L,NC]
#above as it starts with the same ^news-
 
RewriteRule ^news-([^/]*)\.(htm|html|php)$ /news.php?page=$1 [L,NC]
#what do you expect here: -([^/]*) - numbers or letters?
#if number you can try this: -([0-9]+)
the start should be unique for better reference to what you want

I will start the first one with "topic-news" and second to just "news"
Thanks louie, i just changed the second one to "topic-news", thanks again!
 

ziycon

New Member
louie, not sure if you can help me again, i have all the rule rewriting working and all now so i want to fancy it up a bit.

This is what i have:
Code:
RewriteRule ^article/([^/]*)\.htm$ /news_topic.php?id=$1&title=$2 [L]
I want this:
news/title-of-news-article.htm

But every news article is referenced by 'id' which is '$1', i dont want '$1' to show up in the links. And i need spaces rewritten as hypens.

Any help appreciated. Thanks in advanced.
 

louie

New Member
unfortunately you need to pass the id as number in the string as you SQL query is based on that and not on the article name.

Spaces and other characteres has to be changed inside the page while creating the a link. Easy done using preg-replace function

PHP:
$article_name = preg_replace('#[^a-zA-Z0-9]+#','-',$row['article_name']);//replace anything that is NOT a number or letter with -

Now the rule could be:
Code:
RewriteRule ^article/id([0-9]+)/([^/]*)\.htm$ /news_topic.php?id=$1&title=$2 [L,NC]
 

ziycon

New Member
Code:
RewriteRule ^article/id([0-9]+)/([^/]*)\.htm$ /news_topic.php?id=$1&title=$2 [L,NC]
What output will this give, Got Got it working, just needed to remove the 'id' after 'article/', thanks again for your help.
 

louie

New Member
something doesn't look right but if it's working like that and you are happy with it then leave it the way it is.
 
Status
Not open for further replies.
Top