Forum Moderators: phranque
I'm not sure how familiar you are with IP.Board and IP.Content.. well, when you activate .htaccess redirection in the ACP, you get a .htaccess file generated like so:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L] Now, with IP.Content - I am using IPC to put content onto the 'Featured' section of my site. It grabs content from a hidden forum and displays it - simple. An example URL for a view page is http:// mydomain.com /featured/view.php?group=fm&article=7822. The forum board itself is within /community.
So, I've tried adding in some SEO to the links to put the title into the URL for these view pages. I can deal with the PHP side of things no problem, that's simple (in fact, I already have that covered), what is getting me is the RewriteRule. I want the URL to look something like this instead: http:// mydomain.com /featured/article/fm/7822-this-is-my-article-title.
I'm not a massive .htaccess guy... so have tried my best to get this working by adding these lines into the .htaccess file mentioned above:
RewriteRule ^/featured/article/(.*)/(.*)-(.*)$ /community/index.php?app=ccs&module=pages§ion=pages&folder=featured&page=view.php&group=$1&article=$2&title=$3 [L]
RewriteRule ^/featured/article/(.*)/(.*)-(.*)$ /featured/view.php?group=$1&article=$2&title=$3 [L] The first line uses the FULL url created by IPB to access the page, the second URL is the 'semi-friendly' one created by the IPC application which can be user-defined. The problem is, both of these attempts result in me getting a neat little 404 Not Found page.
If anyone here can recommend what to do to fix this - it'll be appreciated. If you need any more details - just let me know and I'll try and hook you up with what you need. If you need more contact with me - email address is in profile.
Thanks a lot,
Lewis :)
Also, you would be wise to avoid the use of the promiscuous and greedy ".*" regex pattern unless absolutely necessary -- and especially multiple occurrences in a single pattern. Your current patterns will result in hundreds, thousands, or even tens of thousands of 'back-off-and-retry' matching attempts for every HTTP request for any "/featured/article/" URL-path.
For your first rule as an example, I'd suggest:
RewriteRule ^featured/article/([^/]+)/([0-9]+)-(.+)$ /community/index.php?app=ccs&module=pages§ion=pages&folder=featured&page=view.php&group=$1&article=$2&title=$3 [L]
Jim
Help appreciated there. Will keep everything on board in future. Once again though (like I expected), I get a normal 404 error.
Perhaps I should clarify the system I have working.. might help a bit.
I have two .htaccess files on my site, one direct in /public_html and one in /public_html/community.
The content of the htaccess in the root directory is:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L] The content of the htaccess in the /community directory is:
RewriteEngine On
RewriteBase /community/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\..+$
RewriteRule . /community/index.php [L]
Anyhow - adding the line you supplied (into either file) is causing the 404 problem.. I'm wondering if the RewriteBase or those RewriteCond lines are messing with the remainder of the script - removing them however, either causes all pages on my site to get 404, or causes a Internal Server Error (which is not being documented in my server log)
Once again.. thanks for any help.
Lewis
None of this code affects your URLs, as both rules above are internal rewrites. URLs are *defined* by the links on your pages, and nothing on the server can "change" them once they appear on your pages. mod_rewrite can either redirect a client-requested URL, or it can change the URL-to-filepath association of a client-requested URL, but it cannot change a URL.
I assume that you added the new rule ahead of the existing one in /.htaccess. If not, that's where it must go.
[added] Look at your server error log for 500-Server Error information, not the server access log.
Jim
Well, I've tried adding the line you supplied above (with the RewriteRule) above the "RewriteRule . /index.php [L] " line, and the RewriteCond lines, and I still get the 404 message. So, I tried adding in a simple redirect:
RewriteRule ^mypage.php$ /index.php [L]
The Internal Server Error messages are not being recorded in the error log at all - so I can't work from them either. Normally (I have received them myself before) they are getting recorded - so I don't think there is a problem that side of things.
This seems to be a very strange problem - and I am quite literally stuck into a corner now. Could it be something as simple as a Apache config problem? The trouble with that is we are currently using shared hosting (of with .htaccess use IS enabled btw), and as far as I can tell, we have no way to configure anything.
Lewis.
mod_rewrte does not 'edit' your pages, it simply modifies the mapping of incoming URLs, as requested by HTTP clients, to the filespace on your server. The link you publish on your page is the URL, and there is nothing that anything anywhere can do to change it -- the URL is defined by appearing in a link on a page, even if that URL does not resolve to an existing resource anywhere on the Web.
Jim
The issue I have though is with the rewriterule, as when accessing the "http://example.com/featured/article/fm/8321-fm-club-2010" link, I get a 404 not found, because the URL is not remapping to "http://example.com/featured/view.php?article=8321&group=fm&title=fm-club-2010" correctly for some strange reason (which is what I am needing the help with)
I can deal with all the PHP changes to get the URL 301 redirecting if it is incorrect etc after actually getting the rewriterule working correctly.
RewriteEngine on
#
# Rewrite featured articles to community/index.php script with query string
RewriteRule ^featured/article/([^/]+)/([0-9]+)-(.+)$ /community/index.php?app=ccs&module=pages§ion=pages&folder=featured&page=view.php&group=$1&article=$2&title=$3 [L]
#
# Rewrite non-blank /community URL-path requests with no filetype and which
# do not resolve to existing files or directories to /community/index.php
RewriteCond %{REQUEST_URI} !\..+$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^community/. /community/index.php [L]
#
# Rewrite all other non-blank URL-path requests to /index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Tested that code and the RewriteRule for the community and all the other areas work, but once again, my /featured/article links do not.
Is there a possible way to find out exactly where the requests are trying to route to (ie: the /community/index.php bit is incorrect) that I could code onto my 404 page to try to look at?
Lewis
app=ccs&module=pages§ion=pages&folder=featured&page=view.php&group=fm&article=8321&title=fm-club-2010 So - from what I can tell it looks like it is sending the request to the right page, but it is missing the correct folder in the redirect? I can't help but think it is something to do with the /community RewriteRules?
Please remember that we don't know your site at all, and have no way to tell correct from incorrect unless you state things explicitly. From the query string you posted, it appears that some other agent has redirected or rewritten this request, as many of the parameters shown do not appear in the rules discussed above.
Jim