Jump to content

cags

Staff Alumni
  • Posts

    3,217
  • Joined

  • Last visited

Everything posted by cags

  1. Why is it any more in our interest to fix it than it is yours? It's as much your board as it is anyone else who's a member (with the exception of PHPFreak).
  2. You can parse HTML with Regex, it is just generally not the best way. Normally far easier/simpler to use some kind of DOM. It sounds like what you are talking about is the difference between Greedy and Lazy pattern matching. By default a PCRE pattern is greedy, you need to make it lazy.
  3. Ahh.. because you are allowing a forward slash in the pattern it's matching the one at the end so it's attempting to load food/register/.php. I'm going to have to make assumptions that your .htaccess file is in your root file and that the register.php file is within the food folder Options +FollowSymLinks RewriteEngine On RewriteBase / RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule ^food/register/?$ food/register.php [NC,L]
  4. Define doesn't work. That should 'work' fine in as much as it should display the correct page. If your paths aren't absolute for things like image/css/js files then it may not 'look' right.
  5. That's because you are using a relative path for src, which is no longer correct as the URL is seen as being in a different folder. I explained this to somebody else yesterday. http://www.phpfreaks.com/forums/index.php/topic,302823.0.html
  6. You just need to make all the links on your site look like /event_info/id/1, not this /event_info.php?id=1.
  7. As I said, you are not understanding how it works. This mod_rewrite rule will not change your URL at all, that is not what making 'pretty URLs' is all about. It will simply Alias the address so you can access it with a different URL. If you can type http://localhost/test/event_info/id/1 into your address bar and see the same page as if you type http://localhost/test/event_info.php?id=1, then it is working fine.
  8. You don't really explain what the problem is, assumably it's not working for you. Firstly your understanding (like 90% of peoples) seems to be a little backwards. The first half of a RewriteRule is what matches against what is requested by the clients browser i.e the address the user sees in the address bar. The second half corresponds to the file which you wish to show the user. Therefore assuming there are no errors in your rule, if you were to type http://domain/event_info/id/10 into the address bar, then the user would see the same page as if they typed in http://domain/event_info.php?id=10. This means that you need to change all URLs in your site to the 'pretty' format e.g. event_info/id/10. Secondly, ideally you will need to be more specific with your regular expressions. You should anchor the pattern at the start and the end and avoid using . as much as possible. Assuming an ID is numeric then I would use a rule along the lines of... RewriteRule ^event_info/id/([0-9]+)/?$ /event_info.php?id=$1 NB: The forward slash before the event_info may not be required, it depends on exactly where the rule is being written. If you get a 404 without it, try adding it in as I did.
  9. That is because with the trailing slash you are essentially in a different 'directory', so relative URLs will not work, therefore if your links for things like CSS, JS and Images are something like 'images/header.jpg' or 'css/style.css' then the browser will look in the wrong location as it will be trying to look in '/about/images/header.jpg' instead of '/images/header.jpg'. The solution is to make all links to external files absolute paths or make them relative to root (begin with a forward slash).
  10. In your OP you have two rules, one without a trailing slash and one with. You should note that in my first post I used Regex to make the forward slash optional (that's what the question mark means in that situation). If you use that rule then either should work.
  11. You are miss-understand what mod_rewrite does. Type www.domain.com/home/ in your address bar, if you see the page loading then your mod_rewrite is working. You should change the links in your site to point at that address.
  12. Define not working. Not doing anything noticable, 404 server error, 500 server error, shows wrong page, something else? How are you testing it? Are you typing in (or clicking on an address) such as www.domain.com/index.php?str=home and expecting it to magically change? Given a request for: www.domain.com/home/ And the following .htaccess: Options +FollowSymLinks RewriteEngine On RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?str=$1 You should see the contents of * **: www.domain.com/index.php?str=home *If you receive a '500 Internal Error' then you probably don't have mod_rewrite enabled. **If you receive a '404 Page Not Found' error, then you probably want a forward slash directly before index.php.
  13. Something like this may work... RewriteCond %{HTTP_USER_AGENT} ^$ RewriteRule .* - [F,L]
  14. I'm not certain it will work for you but I recently came across the NS flag, perhaps you could have some joy with it.
  15. Well the simple answer is you fix your site so that it uses the 'pretty URLs' not the ones with a query_string. A 'hacky' way of preventing it is to track which you've redirected... RewriteCond %{QUERY_STRING} !rewritten=true$ RewriteCond %{QUERY_STRING} ^month=([0-9]+)&year=([0-9]+) RewriteRule ^newsArchives.php$ /newsArchives/%1/%2/? [R=302] RewriteRule ^newsArchives/([0-9]+)/([0-9]+)/?$ /newsArchives\.php?month=$1&year=$2&rewritten=true
  16. A3: What he said. But bare in mind that an empty string would be considered valid by that Regex. You could also use something like ctype_alnum.
  17. It's a regular expression designed to search $data for the string... top.location.replace("http://www.bebo.com/SignIn.jsp") ...case insensitively. As it doesn't actually use any special regex syntax it may have just as well have used... stripos($data, 'top.location.replace("http://www.bebo.com/SignIn.jsp")');
  18. You'll need to set-up a 'proper' localhost set-up, by creating a vhost for each project you do. I wrote/recorded this awhile ago before I knew a great deal about Apache configuration, but it get's the main points across... http://phpacademy.info/forum/viewtopic.php?f=31&t=911
  19. That's because it's you that has it backwards. A RewriteRule is simply an Alias, that allows you to use the pattern matched in the first half as a valid link to the second. ^buy/$ /buy.php [L] Will take requests for http://domain/buy/ and serve up http://domain/buy.php. To test this rule you would have to enter http://domain/buy/ in the address bar, or have a link that has a href of http://domain/buy/
  20. RewriteCond %{QUERY_STRING} ^user=(.*)$ RewriteRule ^highscores$ /user/%1/? [R=302,L] Works fine for me.
  21. What is the exactly query string in the URL that you are using?
  22. Yes, I didn't realise your .htaccess file was within the comments directory, I thought you had it in the sample directory. The URL you are matching against in a RewriteRule is only relative to the position of the .htaccess file so although the REQUEST_URI is /sample/comments/68, you are only actually matching against the 68 part if your .htaccess file is in your comments directory. Either move the .htaccess file up a directory into the sample folder or remove the 'comments/' part from the RewriteRule.
  23. For a finite number of sub-domains you could use something like... RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteCond %{HTTP_HOST} !^admin\. [NC] RewriteCond %{HTTP_HOST} !^members\. [NC] RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301] Or if all your domains are in the same TLD... RewriteCond %{HTTP_HOST} ^[^.]+.com [NC] RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301] Depending on what domains you are working with will depend on what is the best solution.
  24. Just as a word of warning, this will mess-up if you have any subdomains as it will also redirect http://subdomain.domain.com to http://www.subdomain.domain.com.
  25. Yes, it means that is not matching the actual URL. Not the easiest thing in the world to troubleshoot. Try placing just this in a .htaccess file. RewriteEngine On RewriteCond %{REQUEST_URI} !hmm.php RewriteRule ^(.*)$ /hmm.php?url=$1 [R=302,L] And visit http://www.domain.com/sample/comments/68, see what comes up in the address bar.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.