Forum Moderators: phranque

Message Too Old, No Replies

I want to rewrite dynamic urls plz help

         

fsmobilez

12:54 pm on Feb 24, 2009 (gmt 0)

10+ Year Member



Please help me rewriting my dynamic urls script

http://www.example.com/subfolder/jokes_category.php?cat_id=1
http://www.example.com/subfolder/jokes_category.php?cat_id=anynumericvalue

into something like this

http://www.example.com/subfolder/category/page1.html
http://www.example.com/subfolder/category/page2.html

i am trying this but its not wokring

Options +FollowSymLinks
RewriteEngine on
RewriteRule jokes_category/cat_id/(.*)/ jokes_category.php?cat_id=$1
RewriteRule jokes_category/cat_id/(.*) jokes_category.php?cat_id=$1

jdMorgan

4:23 pm on Feb 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Where in your filesystem did you place this code -- In the root diretory at example.com/.htaccess, or in the subfolder at example.com/subfolder/.htaccess?

Jim

fsmobilez

4:34 pm on Feb 24, 2009 (gmt 0)

10+ Year Member



i added in

example.com/subfolder/.htaccess

fsmobilez

4:36 pm on Feb 24, 2009 (gmt 0)

10+ Year Member



well this is the rule which i tried In the root diretory at example.com/.htaccess

Options +FollowSymLinks
RewriteEngine on
RewriteRule http://www.example.com/jokes_category/(.*)/(.*)/$ /sms/jokes_category.php?$1=$2

[edited by: jdMorgan at 6:03 pm (utc) on Feb. 24, 2009]
[edit reason] example.com [/edit]

fsmobilez

4:40 pm on Feb 24, 2009 (gmt 0)

10+ Year Member



SIR I have read almost all of ur threads in this site and tried different variations but cant accomplish my desired url

jdMorgan

5:43 pm on Feb 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The RewriteRule pattern changes depending on where the .htaccess file containing this code is located; URL-paths matched by RewriteRule are "localized" to the .htaccess file's directory.

In any location, the substitution path must contain the full path from DocumentRoot to your script.

In "/subfolder/.htaccess":


Options +FollowSymLinks
RewriteEngine on
#
RewriteRule ^jokes_category/cat_id/([^/]+)/?$ /subfolder/jokes_category.php?cat_id=$1 [L]

- or in "/.htaccess"

Options +FollowSymLinks
RewriteEngine on
#
RewriteRule ^subfolder/jokes_category/cat_id/([^/]+)/?$ /subfolder/jokes_category.php?cat_id=$1 [L]

Note that by making the trailing slash optional, two rules are reduced to one. However, this allows two URLs for the same "page," which is a duplicate-content problem waiting to happen. You should pick either all-trailing-slash URLs or no-trailing-slash URLs, and link to only one of these variations. Then you should add a rule to externally redirect the non-preferred URL-format to the preferred format.

For best results, each object (page, image, etc.) on your site should be accessible by one and only one URL -- termed "the canonical URL." All other variations of domain name, port number, URL, and query string should be redirected to the canonical URL.

Jim

[edited by: jdMorgan at 6:02 pm (utc) on Feb. 24, 2009]

fsmobilez

5:57 pm on Feb 24, 2009 (gmt 0)

10+ Year Member



in above post my site link is posted by mistake , u can edit that

and yes i added the code u posted here in my .htaccess but still not working

Caterham

7:34 pm on Feb 24, 2009 (gmt 0)

10+ Year Member



"Not working" means 404 not found?

fsmobilez

10:51 am on Feb 25, 2009 (gmt 0)

10+ Year Member



i mean no change in dynamic urls after posting this code in .httaccess

jdMorgan

1:10 pm on Feb 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You cannot change a URL with mod_rewrite. You must link to the static URL, and then use mod_rewrite to accept the request for the static URL and call your script after moving the variables in to the query string where your script requires them.

See this thread in our Forum Library: Changing Dynamic URLs to Static URLs [webmasterworld.com]

Jim