Forum Moderators: phranque

Message Too Old, No Replies

Dynamic to static url problem

changing dynamic to static url

         

kenchix1

3:44 am on Dec 13, 2006 (gmt 0)

10+ Year Member



My url is something like :

[widgetc0.c0m...]
[widgetc0.c0m...]
[widgetc0.c0m...]

and I would like it to be change/rewritten to :

[widgetc0.c0m...]
[widgetc0.c0m...]
[widgetc0.c0m...]

I read the procedure on how to change a static url to dynamic url and created this .htaccess file with the following codes but I can't get it to work properly:

---------------000----
Options +FollowSymLinks
RewriteEngine on

RewriteRule ^k/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /topsites.php?k=$1&r=$2 [L]

RewriteRule ^s/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /redir.php?s=$1 [L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /topsites\.php\?k=([^&]+)&r=([^&]+)$
RewriteRule ^/topsites\.php$ [widgetc0.c0m...] [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /redir\.php\?s=([^&]+)$
RewriteRule ^/redir\.php$ [widgetc0.c0m...] [R=301,L]
--------------------000----

my problem is it always says 404 error. aside from that, the parameter "r" on the "topsites.php" is optional so I don't know how I will declare it. these are just two of the php scripts that I need to redirect and rewrite, I'll add the others as soon as I get this thing working.

any help will be highly appreciated.

Thanks in advance.

jdMorgan

3:54 am on Dec 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The first two rewrite rules require five slash-delimited subdirectories after "topsites", whereas your example URLs have only two and one, respectively. I'm not sure why you didn't make the required changes, since your other modifications seem spot-on, or at least very close...

Comment-out the second two rules until you get the first two working -- They implement a 'luxury' search-engine-results clean-up function that you won't need until you get the first rules working, so keep the file simple until then.

As written, the code must reside in .htaccess in your '/topsites' subdirectory in order for the patterns to match. Otherwise, you'll need to adjust the patterns to suit.

Jim

kenchix1

4:36 am on Dec 13, 2006 (gmt 0)

10+ Year Member



thank you very much. I modified the code and BUT it only works if I put the optional "r" parameter. such as :

[widgetc0.c0m...] -- this will throw 404 error
[widgetc0.c0m...] -- this redirects properly

-------------------------------
Options +FollowSymLinks
RewriteEngine on

RewriteRule topsites/k/([^/]+)/([^/]+)/?$ topsites.php?k=$1&r=$2 [L]

RewriteRule redir/s/([^/]+)/?$ /redir.php?s=$1 [L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /topsites\.php\?k=([^&]+)&r=([^&]+)$
RewriteRule ^/topsites\.php$ [widgetc0.c0m...] [R=301,L]

#RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /redir\.php\?s=([^&]+)$
#RewriteRule ^/redir\.php$ [widgetco.c0m...]
-----------------------------

thanks again.

jdMorgan

4:57 am on Dec 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Either handle each case with a rule:

RewriteRule ^topsites/k/([^/]+)/([^/]+)/?$ topsites.php?k=$1&r=$2 [L]
RewriteRule ^topsites/k/([^/]+)/?$ topsites.php?k=$1 [L]

...or allow the "r=" parameter to be passed as blank to your script if it's not present in the requested URL:

RewriteRule ^topsites/k/([^/]+)(/([^/]+))?/?$ topsites.php?k=$1&r=[b]$3[/b] [L]

Your script may or may not accept the second solution, and using it may have side-effects within the script -- I don't know.

Jim

kenchix1

10:11 am on Dec 13, 2006 (gmt 0)

10+ Year Member



thanks for all the help! :)

though one of my page can't seem to create a static link because it is using a Form with a button and whenever you click on it, a dynamic url appears on the address box.

I'm using input type=submit and $_GET on the Php script to get the values of the variables.