Forum Moderators: phranque

Message Too Old, No Replies

Dynamic to Static

Need help with rewrite rule.

         

onedodd

9:36 pm on May 10, 2005 (gmt 0)

10+ Year Member



Hi,
I have seen all the mod_rewrite posts here but could not translate anything into success so here is another mod_rewrite post for help.

I have been trying with absolutely no success to change some dynamic URL's to static URL's by using mod_rewrite.

Dont know how this would affect anything but I currently have this in my .htaccess so I can use some SSI's on regular .html pages, for including link tables, common footer etc:

Options Indexes FollowSymLinks Includes
AddType application/x-httpd-cgi .cgi
AddType text/x-server-parsed-html .html .htm

------------------------------------------------------

I am trying to change this and other dynamic URL to a static URL mainly for the SE's and getting some hard to index links indexed.

I want to change this type link:
*ww.example.com/bass-reports/index.php?action=showentries&catid=4

to something like this:

*ww.example.com/bass-reports/showentries/4.html or how ever it works out.

I have tried this with nada results.

RewriteEngine On
RewriteRule ^/(.*)/(.*).html /index.php?action=$1&catid=$2

I have tried many ways. I have tried putting htaccess in the sites root. I have put the htaccess in the dircetory where the webpages are. I don't know if I am missing something in the htaccess or what.
the only thing I know for sure is I am outside my area of knowledge and any help would be great.

Am I even on the right track?

Thank You, Joe Dodd

[edited by: jdMorgan at 6:35 pm (utc) on May 12, 2005]
[edit reason] Removed specifics. [/edit]

jdMorgan

9:52 pm on May 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Joe,

Welcome to WebmasterWorld!

URL-paths as seen by RewriteRule in .htaccess are stripped of their leading slash, so your rule would never match. Tips: Using ".*" multiple times in a pattern is very inefficient. Literal periods in patterns need to be escaped by preceding them with "\". Use the [L] flag unless you have a reason not to.

I'd suggest:


RewriteRule ^([^/]+)/([^.]+)\.html$ /index.php?action=$1&catid=$2 [L]

This code would go into the bass-reports directory. Alternately, you could use

RewriteRule ^bass-reports/([^/]+)/([^.]+)\.html$ /bass-reports/index.php?action=$1&catid=$2 [L]

in your Web root directory.

Now if you request the static URL, mod_rewite will pass control to index.php with the two query string parameters.

Jim

onedodd

5:41 pm on May 12, 2005 (gmt 0)

10+ Year Member



Thanks for your help on this.
unfortunatly I was unable to get it to work.
I copied it charatcer for character.
Tried both versions in the root and in the local directory where the .php file is.
I wrote my host and they said all I should need to turn on mod_rewrite was : RewriteEngine On .

So there should be no problems there.

I even tried the same concept with this link at my other site-- no luck. Same result as the original links in the first post.

*ww.example.com/business/search_result.php?search=Browse&category=Fishing+Charters

Is there something I am missing in my .htaccess file? My code didn't work nor yours so that leads me to believe that I may be forgetting something in the htaccess file.

I appreciate any help, I'd like to try one more time.
I've tried the apache site with no luck.

Thanks Joe

[edited by: jdMorgan at 6:33 pm (utc) on May 12, 2005]
[edit reason] No specific URLs, please. [/edit]

jd01

6:22 pm on May 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Joe,

You might try adding QSA to your directives: (I have to do this some times, even when I don't think I should.)

RewriteRule ^([^/]+)/([^.]+)\.html$ /index.php?action=$1&catid=$2 [QSA,L]

RewriteRule ^bass-reports/([^/]+)/([^.]+)\.html$ /bass-reports/index.php?action=$1&catid=$2 [QSA,L]

Justin

** Thinking this had already been covered, I left it out of the original... Where do your pages link to? It almost looks as though you are going backward. IOW do the links on your page that a user would click go to the static or dynamic URL?

onedodd

8:05 pm on May 12, 2005 (gmt 0)

10+ Year Member



I will give it another shot this evening.

Here is the original exact link a user clicks. Untouched and unaltered. I changed the first w to * so it would show as a link.

*ww.fishingreporters.com/bass-reports/index.php?action=showentries&catid=1

On the apache page they had instructions for going from a static URL to a dynamic URL but I don't know why one would want to do that.

[httpd.apache.org...]
[httpd.apache.org...]

We will see what happens.

Thank You

jd01

8:36 pm on May 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You are definitely going the wrong way, nothing cited above will work.

Start here:

[webmasterworld.com...]

Justin

onedodd

9:16 pm on May 12, 2005 (gmt 0)

10+ Year Member



Are you saying mod_rewrite will not change the data base created links?

Are you also saying that if I take this link:
*ww.example.com/business/search_result.php?search=Browse&category=Fishing+Charters

the link created by the .php script and use it as a hard link on say my home page for example then I can change the look of the link with mod_rewrite?

From what I gather the link must be an actual 'hard link' that a user clicks before you can use mod_rewrite to change it in the way I was looking to do.

Otherwise I am lost and will read the other thread fully.
Most forums make it sound so easy - ie change your dynamic links to search engine friendly links. That makes one think you can use mod_rewrite to alter the link as it is created by the php script.
Told you I was lost. Also told you I was outside my knowledge on this stuff.
Is there a way to change the dynamic or database link to a SE friendly link?

Thanks, Joe

jd01

9:47 pm on May 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There is a way to do just about anything you would like. The complexity of doing it is the only thing that changes.

The simplest way to do what you are attempting is to link to the html page/address you would like to have displayed. (The page this link goes to does not exist, except in the browser.) Then you can use mod_rewrite to serve the contents of your php page to the URL appearing in the browser.

Please, note with mod_rewrite there are only two ways to have a URL appear in a browser: 1. The URL is requested, either through a link, or actually typed in to the address bar. 2. To externally redirect to the URL. EG 301 or 302 Redirect, that will show the new location in the browser.

I think reading the other thread would be very helpful for you.

Justin