This expression will match store/d1/d2/d3/f4.html because regex by default will grab as much as it can and $1 will be /d1/d2/d3 - not something you really want. Use this one instead: ^store/([^/]+)/([^/]+)\.html$ J.D.
HI everyone, Thanks for a great guide. I had a quick question. I have mod_rewrite and my PHP pages setup as so: /page_detail.php?pageID=1 <-- the number is the incremental unique ID from the MySQL database so the rest of the content pages are: /page_detail.php?pageID=2 /page_detail.php?pageID=3 ...and so on. my .htaccess file looks like this: --------------------------------------------------- RewriteEngine on Options +Indexes Options +FollowSymlinks RewriteRule -([0-9]+).html page_detail.php?pageID=$1 [L] --------------------------------------------------- and my generated pages look like this: --------------------------------------------------- "/page-title-here-1.html" Note the trailing "-1" at the end of the name which is the unique ID from the DB. How can I get rid of it so I can see "/page-title-here.html" without the "-1" Any help would be greatly appreciated. Thanks
Great that you started this thread, I have tried multiple codes in .htaccess, Including the one above me. But they don't work and the links stay dynamic. Could you please help me out. Best regards, Eiso
guru seo you can't really get rid of the dynamic element. As apache translates a static htm into your require code how would it know that mysite.htm refers to mysite.php?id=8 ?? you can get rid of the - so it looks like page1 page2 page3 etc. RewriteRule page([0-9]+).html page_detail.php?pageID=$1 [L] Also how would SE's determine various pages all mypage.htm but with various titles etc etc...? If you have unique titles you could use these instead and do the db lookup based on title e.g. mypage.php?subject=How_to_do_mod_rewrite RewriteRule subject_([A-zA-Z_]+).htm page_detail.php?subject=$1 [L] could give you a translatable static htm like mmydomain.xxx/subject_how_to_do_mod_rewrite.htm in your php you can than look up the content for the titel instead of using page id Expat
Expat, I was thinking among the same lines, the work around would be to change the SQL query to the page_detail.php?page_title=page_title as opposed to the pageID. I will give it a shot. Thanks again for your feedback, it is greatly appreciated.
Make sure you quote the period - otherwise your rule will match something like page1_html. Also, unless you are trying to match a sub-word, make sure to prefix the regex with the caret, otherwise it will match something like this_is_my_page1_html.html. J.D.
Hmm, is it really worth doing this considering a lot of serach engines are getting better with indexing dynamic URLS? Won't it increase server load? I've got a website that uses the index.php?page= format... and I link to all my pages using this format. If I implement this, will I need to change the way I link to my pages or is it all automated?
I've never noticed any server load increase. And I have about 46 Rewrite lines on my Amazon stores. The only time my server was ever effected was when I got Googlebombed!!!! (ie Google going through your sites so fast that it slows down, crashes or almost crashes the server.) Solution to that was optimizing Apache.
Awsome, seems to be working great on my site. It however messes up the ad codes for some reason. Strange... would there be any reason to this? Some of the ads default to a normal *.html page on the server... so when it does do this, it also loads the index.php template as well... Is there a way to fix this?
Make rewrited URLs have an extension that you don't use any where else. Don't use .htm any where? Rewrite all the URLs to end with that.
Hmm as a general query, if the urls on the site is in the form of index.php?page=whatever etc... is it worth using mod rewrite considering search engines are able to index these dynamic urls?
Let me ask a question: regardless of mod_rewrite or not do your dynamic pages have dynamic title and description as well? As they obvously have dynamic content. Because if you where a SE would you index and show 20 pages with the same title (and to a lesser extend description)? For listings in minor engines and directorytype sites as well as deeplink exchanges a mod_rewrite page url is easier for all to handle. The major se's all happily index two vars (?xxx=xxx&yyy=yyy) but they hate same titel.... e.g its easier and better to ask a webmaster to link to /sms-arrivals-lhr.htm than to link to /sms.htm?type=arrivals&apt=lhr Cheers Expat
Hmm point taken. I've installed the mod rewrite because it makes everything look so much neater... but I am running into some trouble with the title. Basically, I load all my pages within a template index.php and thus, all the site pages have the same title --> I've also noticed this problem when I index the site pages in the site search engine I use. Short from going into every single file (which I don't think will do anything because I've tried inserting meta and title tags in the content pages but they're 'overwritten' by being loaded by the index.php template file), what other options would be possible? Could a similar mod like mod_rewrite be the answer?
don't want to digress too much but using the vars to injecting them in the title is one way. I have title and desc in the content db's and use a default if non found. if mod-rew /sms-arrival-heathrow-lhr.htm from sms.htm?type=arrival&apt=heathrow&cde=lhr <title>Your SMS service for <?php echo $type?> at <?php echo $apt." (".$cde ?>) blah blah blah</titel> is the easy sollution...... Expat
Thanks expat and everyone in this thread ^_^ Your help much appreciated. The dynamic titles now exists (woohoo!) and the mod_rewrite successfully installed
OK, I've been going nuts with this one..maybe you can help? I've been trying the infamous http://domain.com to http://www.domain.com redirect. I must have done a dozen different ones. None worked. Why won't this one work? RewriteEngine On RewriteRule http://domain.com/* http://www.domain.com/$1 [L,R=301] (Note: I did get one to work but it turned http://www.domain.com/ into http://www.domain.com// which would bring the same problem...!) PS> I had to do a few rewrites for other purposes and no, didn't notice any extra CPU time.