Unstoppable Domains

[Resolved] Mod-rewrite

Spaceship Spaceship
Watch

liam_d

The original NP Emo KidEstablished Member
Impact
25
mod-rewrite

Well i am trying to use mod re-write and have put this in a .htaccess file but it does nothing:
Code:
RewriteRule ^category/([0-9]+)?$ index.php?menu=showcat&cid=$1

Any ideas?

I'm trying to change "index.php?menu=showcat&cid=4"
to like
/category/4/

please help

thanks!
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
A guess...

RewriteRule ^/category/(.*) /index.php?menu=showcat&cid=$1

If that works please reply back :)
 
Last edited:
0
•••
Is there something i need to actually put into my php script itself to pick up the use of mod-rewrite??
 
0
•••
No... but your .htaccess should look like this

Code:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/category/(.*) /index.php?menu=showcat&cid=$1

It'll only work if you have mod_rewrite.c, and of course my regex might be wrong.
 
Last edited:
0
•••
Well i put that in the .htaccess and it did nothing, think it's time to contact my host, they said it's on.
 
0
•••
Code:
RewriteEngine on
RewriteRule ^category/([0-9]+)$ http://www.YOUR_DOMAIN.com/index.php?menu=showcat&cid=$1 [L]

There is no need for the conditional statements that Danltn used. Also this only works if there is no trialling slash. If you want it to work if there is a trialling slash have:-

Code:
RewriteEngine on
RewriteRule ^category/([0-9]+)/?$ http://www.YOUR_DOMAIN.com/index.php?menu=showcat&cid=$1 [L]

This definitely works as I have just tested it on my own server.
 
0
•••
Have you actually changed the links to use the new, rewritten URLs?

Also, here is a .htaccess that will work for URLs with and without a slash, provided the categories are alphanumeric.

Code:
RewriteEngine On
RewriteBase /
RewriteRule ^category/([a-zA-Z0-9]+)(/|)?$ index.php?menu=showcat&cid=$1
 
0
•••
The following should work
(tested myself)
Code:
RewriteEngine On
RewriteRule ^category/([a-zA-Z0-9]+) /index.php?menu=showcat&cid=$1
Joe
 
Last edited:
0
•••
Code:
RewriteEngine On
RewriteBase /
RewriteRule ^category/([0-9]+)(/|)?$ index.php?menu=showcat&cid=$1

Final go. :p
 
0
•••
Danltn said:
Code:
RewriteEngine On
RewriteBase /
RewriteRule ^category/([0-9]+)(/|)?$ index.php?menu=showcat&cid=$1

Final go. :p

Why are you checking for a | in your regexp? (looking back it seems because mikor is using it, are you expecting it to have some special behavior?)

TheArbiter said:
The following should work
(tested myself)
Code:
RewriteEngine On
RewriteRule ^category/(.*) /index.php?menu=showcat&cid=$1
Joe

If the category is going to be numerical it would be best to ensure that it is in fact numerical (although the check should also be made within the script)
 
Last edited:
0
•••
peter@flexiwebhost said:
Danltn said:
Code:
RewriteEngine On
RewriteBase /
RewriteRule ^category/([0-9]+)(/|)?$ index.php?menu=showcat&cid=$1

Final go. :p

Why are you checking for a | in your regexp?

I just edited Mikor's, so it would only work it 0-9
 
0
•••
Danltn said:
I just edited Mikor's, so it would only work it 0-9

Yeah noticed that after I posted.

Anyway as I posted above, if he wants to allow slashes you simply do:-


Code:
RewriteEngine on
RewriteRule ^category/([0-9]+)/?$ http://www.YOUR_DOMAIN.com/index.php?menu=showcat&cid=$1 [L]

The question mark after the slash makes it optional. I prefer also to put the name of the domain in the path of the rewritten rule as if you do not it can cause problems. In this case if you do not use the domain name then you will be forwarded too:-

http://www.YOUR_DOMAIN.com/category/index.php?menu=showcat&cid=1 if you tried http://www.YOUR_DOMAIN.com/category/1 I came across this exact problem while developing my current project.
 
0
•••
"The question mark after the slash makes it optional."

I remember this :hehe:

"I prefer also to put the name of the domain in the path of the rewritten rule as if you do not it can cause problems. In this case if you do not use the domain name then you will be forwarded too:-"

I agree with this as well, although it can cause some fussy problems if you plan on changing domains, but that is rare.

Brilliant job as always Peter :)
 
0
•••
peter@flexiwebhost said:
Why are you checking for a | in your regexp? (looking back it seems because mikor is using it, are you expecting it to have some special behavior?)
The pipe symbol (|) is an OR. Whenever allowing for both a / or not a /, I use (/|)
 
0
•••
Mikor said:
The pipe symbol (|) is an OR. Whenever allowing for both a / or not a /, I use (/|)

the proper syntax for that behavior is the ? which is specifically for something that is optional
 
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Unstoppable Domains
Domain Recover
DomainEasy โ€” Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back