Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
Regular Expression needed for reWrite
I need a regular expression that will capture any title with any number of letters or numbers or hyphens in any order, but which will reject any title with / or ? in it.
My site presently has /title as the url mode but I want to change this to /section/title.
I need the regular expression to prevent 404s and so I can redirect visitors and robots permanently from
http://mysite.com/example-title-1
to
http://mysite.com/section/example-title-1
I’ve been trying to figure this out for some weeks now and also tried plugins but so far without success, so I will be most grateful if someone can answer this.
Offline
Re: Regular Expression needed for reWrite
Have you tried it this way?
RedirectMatch 301 ^/(.*)$ http://mysite.com/section/$1
What problems arise with / or ?
We Love TXP . TXP Themes . TXP Tags . TXP Planet . TXP Make
Offline
Re: Regular Expression needed for reWrite
I’ll try that Bert, but I think that when someone types in
http://mysite.com/section/title
they will get a repeating loop such as:
http://mysite.com/section/section/section/section etc.
That’s why I don’t want it to pick up any / other than the one immediately after mysite.com
Offline
#4 2007-01-28 17:26:27
- marios
- Archived Plugin Author
- Registered: 2005-03-12
- Posts: 1,253
Re: Regular Expression needed for reWrite
Try this:
match string:
^([\w\d-]+\b)$
replacement string:
section/$1
I’m not so sure about the htaccess syntax, but the RE does what you need.
regards, marios
⌃ ⇧ < ⎋ ⌃ ⇧ >
Offline
Re: Regular Expression needed for reWrite
zero, You’re right, it creates a never ending loop, just tried it on my local server.
marios, tried your solution, but I get 404’s.
RedirectMatch 301 ^([\w\d-]+\b)$ http://hcg.valleyhaven.net/textpattern/article/$1
Interesting dilemma.
We Love TXP . TXP Themes . TXP Tags . TXP Planet . TXP Make
Offline
Re: Regular Expression needed for reWrite
Many thanks, marios, I think your way works!
Within htaccess, straight after RewriteEngine On, I put this:
RewriteRule ^([\w\d-]+\b)$ http://mysite/section/$1 [R=301,L]
I haven’t put a RewriteCond or anything else in there. I need more testing to be sure but it seems to work!
Offline
Re: Regular Expression needed for reWrite
zero wrote:
Within htaccess, straight after RewriteEngine On, I put this:
RewriteRule ^([\w\d-]+\b)$ http://mysite/section/$1 [R=301,L]
I didn’t have it in the right place, it does work now. Now one caveat, you can’t have a trailing slash like http://mysite/first-post/ but I guess that’s never going to happen.
marios, sorry I doubted you :)
We Love TXP . TXP Themes . TXP Tags . TXP Planet . TXP Make
Offline
Pages: 1