help with rewrite

Discuss practical ways rearrange URLs using mod_rewrite.

help with rewrite

Postby bender » Sat Aug 09, 2008 9:29 pm

I need to have friendly urls displayed simply for now until I learn how to change them myself. Can someone help? Any help is appreciated.

I need to change this url:

Code: Select all
http://www.example.co.cc/index.php?page=browse&category=1

to
Code: Select all
http://www.example.co.cc/browse-cattery-1.html


I am using this , it is no help!

Code: Select all
Options +FollowSymLinks
RewriteEngine on
RewriteRule browse-cattery(.*)-(.*)\.html$ /index.php?page=$1&category=$2


Thanks in advance,
Bender
bender
 
Posts: 13
Joined: Sat Aug 09, 2008 9:23 pm

Postby richardk » Sun Aug 10, 2008 11:49 am

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^browse-cattery-([0-9]+)\.html$ /index.php?page=browse&category=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby bender » Sun Aug 10, 2008 1:31 pm

sorry to say that didn't work. i remember reading about someone that had troubles with modrewrite not being configured correctly. also one about a rule after Options +FollowSymLinks. i'll keep trying...
bender
 
Posts: 13
Joined: Sat Aug 09, 2008 9:23 pm

Postby bender » Sun Aug 10, 2008 2:18 pm

Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Remove index.php.
RewriteCond %{THE_REQUEST} \ /(.+/)?index\.php(\?.*)?\  [NC]
RewriteRule ^(.*+/)?index\.php$ http://example.co.cc/%1 [R=301,L]

# Remove .php or /.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_URI} ^/(.+)(\.php|/)$ [NC]
RewriteCond %{DOCUMENT_ROOT}/%1.php -f
RewriteRule !^(.+/)?index\.php$ http://example.co.cc/%1 [R=301,L]


# Add the .php back.
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*[^/])$ /$1.php [QSA,L]



this works to remove index.php, found it somewhere on this site....
bender
 
Posts: 13
Joined: Sat Aug 09, 2008 9:23 pm

Postby bender » Tue Aug 12, 2008 10:28 pm

Can the above be modified to get the results I need?


I have this
Code: Select all
http://www.example.co.cc/index.php?page=browse&category=1

I need this
Code: Select all
http://www.example.co.cc/browse-cattery-1.html

Code: Select all
Options +FollowSymLinks

This is what works to remove index.php
[code]RewriteEngine On

# Remove index.php.
RewriteCond %{THE_REQUEST} \ /(.+/)?index\.php(\?.*)?\  [NC]
RewriteRule ^(.*+/)?index\.php$ http://example.co.cc/%1 [R=301,L]

# Remove .php or /.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_URI} ^/(.+)(\.php|/)$ [NC]
RewriteCond %{DOCUMENT_ROOT}/%1.php -f
RewriteRule !^(.+/)?index\.php$ http://example.co.cc/%1 [R=301,L] [/code]


# Add the .php back.
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*[^/])$ /$1.php [QSA,L]


This is what richard gave me to try but it does not work.
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^browse-cattery-([0-9]+)\.html$ /index.php?page=browse&category=$1 [QSA,L]


[/code]

bender
bender
 
Posts: 13
Joined: Sat Aug 09, 2008 9:23 pm

Postby richardk » Wed Aug 13, 2008 12:37 pm

When you use
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^browse-cattery-([0-9]+)\.html$ /index.php?page=browse&category=$1 [QSA,L]

what happens when you go to /browse-cattery-1.html? A 404 error?

Also try
Code: Select all
browse-cattery-([0-9]+)\.html$
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby bender » Wed Aug 13, 2008 7:35 pm

no change in the url at all for either one.

bender
bender
 
Posts: 13
Joined: Sat Aug 09, 2008 9:23 pm

Postby bender » Wed Aug 13, 2008 7:41 pm

Also try
Code: Select all
browse-cattery-([0-9]+)\.html$
[/quote]

do you mean try this? 500 error

Code: Select all
RewriteRule ^browse-cattery-([0-9]+)\.html$ /


I tried this

Code: Select all
RewriteRule ^browse-cattery-([0-9]+)\.html$ /index.php?page=browse&category=$1 [QSA,L]
no change

bender
bender
 
Posts: 13
Joined: Sat Aug 09, 2008 9:23 pm

Postby bender » Wed Aug 13, 2008 8:39 pm

Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Remove index.php.
[code]RewriteCond %{THE_REQUEST} \ /(.+/)?index\.php(\?.*)?\  [NC]
RewriteRule ^(.*+/)?index\.php$ http://example.co.cc/%1 [R=301,L]

# Remove .php or /.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_URI} ^/(.+)(\.php|/)$ [NC]
RewriteCond %{DOCUMENT_ROOT}/%1.php -f
RewriteRule !^(.+/)?index\.php$ http://example.co.cc/%1 [R=301,L] [/code]


# Add the .php back.
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*[^/])$ /$1.php [QSA,L]


Why does this work to remove index.php and the others suggested do not work?

bender
bender
 
Posts: 13
Joined: Sat Aug 09, 2008 9:23 pm

Postby bender » Wed Aug 13, 2008 9:29 pm

This is the line that works to remove index.php;
Code: Select all
RewriteRule ^(.*+/)?index\.php$ http://example.co.cc/%1 [R=301,L


can you help remove
Code: Select all
page=browse&category=1


from
Code: Select all
http://example.co.cc/index.php?page=browse&category=1


and add
Code: Select all
browse_cattery
just after
Code: Select all
http://example.co.cc/
bender
 
Posts: 13
Joined: Sat Aug 09, 2008 9:23 pm

Next

Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 6 guests

cron