simple(?) htaccess rewriting issues

OK I have been messing about with URL rewriting for the last few days and seem to have come to a bit of a dead-end. I have come up with a few solutions that work on some servers and not others, and my hosting company (1and1 - be vary wary of these guys if you choose them as hosts) hasn't been able to help at all.

My problem is this, i want to re-write this url:

/result.php?section=[section name]&url=[url]

to this:

/article/[section name]/[url]/ (adding a trailing slash if there is none)

and ALSO

section.php?section=[section name]


/section/[section name]/ (again adding a trailing slash)

each attempt seems to have different results. currently I am using thhe following, which works locally, but on the live server only the 'articles' rewrite works:

RewriteRule ^article/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ /article/$1/$2/ RewriteRule ^article/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ /result.php?section=$1&url=$2 RewriteRule ^section/([a-zA-Z0-9_-]+)$ /section/$1/ RewriteRule ^section/([a-zA-Z0-9_-]+)/$ section.php?section=$1

Can anyone help me come up with a solution that will work nicely? Thank you in advance, I am really struggling with what seems like something relatively straightforward...

-------------Problems Reply------------

Firstly in order to force the backslash on the end you will need to actually do a redirect...

RewriteRule ^article/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ /article/$1/$2/ [R=302,L]
RewriteRule ^section/([a-zA-Z0-9_-]+)$ /section/$1/ [R=302,L]

Note: I use 302 because 301 can be a pain during testing, once everything is working and you are happy with it change it to 301.

The two remaining rules are the rewrites that simply mask/alias the query_string URL, which should look something like this...

RewriteRule ^article/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ /result.php?section=$1&url=$2
RewriteRule ^section/([a-zA-Z0-9_-]+)/$ /section.php?section=$1

Category:apache Views:0 Time:2010-07-29

Related post

  • simple .htaccess rewrite URL to different directory on same server 2011-08-27

    Ok, I'm clueless here... I need to rewrite a directory structure and all sub-directories within it to a directory within the same server, but a root that is before the directory. For example: and all

  • Simple htaccess rewrite/redirect to search page 2011-10-04

    I have a search form that sends a GET request to a page called search.php. I have rewrite rules set up in my htaccess file that rewrite certain things, like /search, to their respective pages. I simply want to take the search.php?q=query and rewrite

  • htaccess rewrite issue while testing on localhost 2010-06-01

    I'm running OSX (10.6) with Apache with .htaccess enabled. In the htaccess file I have the code: Options +FollowSymlinks RewriteEngine on RewriteRule ^page/([A-Z0-9._%+-]+) index.php?page=$1 [NC] This runs perfectly on my external server and redirect

  • .htaccess rewrite issue - what am I missing? 2011-12-08

    All I want to do is a very simple redirect so that mypage.html is displayed in the browser, but index.php?s=1 is the page that is served up. What am I missing here? redirect 301 /mypage.html index.php?s=1 - this redirects the whole page as expected R

  • Simple .htaccess rewrite? 2010-01-28

    I forgot how to do that and I am stuck. I have a site say and another folder I want when some one visits the he will be redirected secretly to but still see in the URL www.e

  • Problems with a simple URL rewrite (htaccess) 2011-11-17

    I can't get a simple htaccess rewrite to work. RewriteEngine On RewriteRule ^([^/]*)\.html$ /?id=$1 [L] I went to expecting to end up on What's wrong? --------------Solutions------------- This is not how htac

  • simple .htaccess internal rewrite issue 2010-11-18

    I want to do this simple internal write : http://localhost/icore4/t1/js/GeneralJs.js to http://localhost/icore4/js/GeneralJs.js htaccess location icore4/.htaccess htaccess code RewriteEngine on RewriteRule ^(.*)/(.*)$ /$2 [NC,L] bottomline, I want to

  • simple htaccess issue 2011-03-07

    I have a simple htaccess issue. In my localhost I have a folder mysite. mysite has three subfolders. html dev images I have put my htaccess in mysite folder. My rule is if anyone access site through http://localhost/mysite it should read files from h

  • Tips for debugging .htaccess rewrite rules 2012-02-05

    Many posters have problems debugging their RewriteRule and RewriteCond statements within their .htaccess files. Most of these are using a shared hosting service and therefore don't have access to the root server configuration. They cannot avoid using

  • .htaccess Rewrite Question 2009-05-27

    I have a number of pages in my site, as one would expect. For example: index.php submit.php view.php?id=blah I want these rewritten like index/ submit/ view/blah Whats the best way of doing this? --------------Solutions------------- The ways of handl

  • htaccess rewrite rule doesn't work with dashes? 2009-10-27

    my htaccess rule isn't working with rewrite with dashes in: RewriteRule ^([A-Za-z]+)$ index.php?do=$1 [QSA] so, works, however, doesn't I've verified that works so it's

  • htaccess rewrite : subdomain? 2010-11-24

    I am thinking of rewriting my urls, for example: would become Is this possible to do with .htaccess rewrite? Is this wise to do? As opposed to W

  • Simple .htaccess to nginx 2011-03-13

    I need help how to convert this simple .htaccess to ngingx format and i really have no idea where to start with it. I tried to go through nginx docs but they simply overwhelmed me and I need it done now so please help :) RewriteEngine on RewriteRule

  • Simple MOD-REWRITE not working on production server 2011-03-19

    I have an extremely simple static rewrite in my .HTACCESS which worked fine on my dev server, but I can't seem to get it working on the production server (GoDaddy Linux hosting) for the life of me. Code is: # Contact page rewrite RewriteRule ^contact

  • htaccess rewrite still some problems, getting a bit complex eek! 2011-04-14

    Another edition to my .htaccess rewriting saga. Everything is now working to a degree but still have some issues. I have numerous rules to move old urls to new urls, passing variables etc - however there are still a couple of things i need to add, an

  • htaccess rewrite rule enrute 2 times 2011-09-02

    I have a big problem with .htaccess rewrite rule, my code is this: <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php?url=$1 [L,QSA] </IfModule> I

  • Very Simple URL Rewrite withou Regex 2011-09-15

    for a site move I need to hardcode some very simple URL Rewrites. I only see examples with regular expressions but what I need is this: I have a CSV like new URL, old URL, as you see

  • .htaccess Rewrite Rule Problems 2011-10-24

    can anyone help me with htaccess rewrite? I have now links like: but i want something like this Im try with this RewriteEngine on RewriteRule ^profile/([0-9]+) all_user

  • Getting 404 error when using file_get_contents to scrape html from page that has apache .htaccess rewrite rule 2014-05-26

    I'm trying to scrape rendered html from a drupal 7 site. But I'm unable to target the file with file_get_contents or curl or anything because of a rewrite rule. I always get a "404 file not found" error when trying to load any local file from my serv

Copyright (C), All Rights Reserved.

processed in 0.159 (s). 11 q(s)