Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Mod_rewrite

  1. #1
    Code-aholic conor's Avatar
    Join Date
    Nov 2008
    Location
    Monaghan
    Posts
    60
    Post Thanks / Like

    Default Mod_rewrite

    Hi,

    I just used my first mod_rewrite script a few weeks ago and it was fine until now. Now I need more !!!

    This is what I have:

    Code:
    RewriteEngine on
    RewriteCond %{SCRIPT_NAME} !\.php
    RewriteRule ^([^./]*)$ index.php?page=$1 [L]
    That basically tells the server to rewrite http://example.com/Home as http://example.com/index.php?page=Home

    Now what I need to do is keep what is there already and on top of that say rewrite http://example.com/Home/Welcome as http://example.com/index.php?page=Welcome&parent=Home

    But I only want it to do this if something like that is requested - otherwise tell it to use the old script.

    Does anyone know how to do this?

    Thanks

  2. #2
    Senior Member louie's Avatar
    Join Date
    Jan 2006
    Location
    Dublin, Ireland
    Posts
    2,423
    Post Thanks / Like

    Default

    you could try this
    Code:
    RewriteEngine on
    RewriteCond %{SCRIPT_NAME} !.php
    RewriteRule ^([^./]*)/?(.*)?$ index.php?page=$1&parent=$2 [L]
    A better option
    Code:
    RewriteEngine on
    RewriteCond %{SCRIPT_NAME} !.php
    RewriteRule ^([0-9a-zA-Z]+)/([0-9a-zA-Z]+)?$ index.php?page=$1&parent=$2 [L]
    RewriteRule ^([0-9a-zA-Z]+)?$ index.php?page=$1 [L]
    :. Web Design & Development Web Design Ireland
    :. Search Engines Optimization Search Engines Optimization
    :. Car Parts & Accessories Car Parts
    :. Cars Ireland Cars Ireland
    :. I Have 2 Find It Directory SEF Directory

  3. #3
    Code-aholic conor's Avatar
    Join Date
    Nov 2008
    Location
    Monaghan
    Posts
    60
    Post Thanks / Like

    Default

    that does the job except for one thing. If you have a space in either the page or the parent it shows a 404 - not found. Do you know how I could change that? I imagine that you would just need to add a space in with these other characters, but it's not working!
    ^([0-9a-zA-Z]+)
    ^([0-9a-z A-Z]+)

  4. #4
    Senior Member louie's Avatar
    Join Date
    Jan 2006
    Location
    Dublin, Ireland
    Posts
    2,423
    Post Thanks / Like

    Default

    try this and also follow the rewrite rules
    Code:
    (0-9a-zA-Z_- ]+)
    spaces are not recomended as the URL gets converted with %....
    you should use _ or -
    :. Web Design & Development Web Design Ireland
    :. Search Engines Optimization Search Engines Optimization
    :. Car Parts & Accessories Car Parts
    :. Cars Ireland Cars Ireland
    :. I Have 2 Find It Directory SEF Directory

  5. #5
    Code-aholic conor's Avatar
    Join Date
    Nov 2008
    Location
    Monaghan
    Posts
    60
    Post Thanks / Like

    Default

    Thanks louie. That worked but I opted to get rid of the spaces and follow the rules!

    You must forgive me, I have never tried anything like this on a windows server before. I have a .htaccess file, but how can I get the above settings to work on windows? It is possible because wordpress seems to manage it. But it's not working on my windows server (don't bother asking why I have a windows server - it's a long story!). Can anyone suggest anything?

    Thanks

  6. #6
    Senior Member louie's Avatar
    Join Date
    Jan 2006
    Location
    Dublin, Ireland
    Posts
    2,423
    Post Thanks / Like
    :. Web Design & Development Web Design Ireland
    :. Search Engines Optimization Search Engines Optimization
    :. Car Parts & Accessories Car Parts
    :. Cars Ireland Cars Ireland
    :. I Have 2 Find It Directory SEF Directory

  7. #7
    Code-aholic conor's Avatar
    Join Date
    Nov 2008
    Location
    Monaghan
    Posts
    60
    Post Thanks / Like

    Default

    Thanks, I should have known that you would need to pay for it... !!

  8. #8
    Web Slave blacknight's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    9,998
    Post Thanks / Like

    Default

    Quote Originally Posted by conor View Post
    Thanks, I should have known that you would need to pay for it... !!
    It's available with some hosting providers shared hosting plans

  9. #9
    Code-aholic conor's Avatar
    Join Date
    Nov 2008
    Location
    Monaghan
    Posts
    60
    Post Thanks / Like

    Default

    Does anyone know how I could rewrite "Test" as "test.php" if i knew what the name test would be?

  10. #10
    Senior Member louie's Avatar
    Join Date
    Jan 2006
    Location
    Dublin, Ireland
    Posts
    2,423
    Post Thanks / Like

    Default

    Code:
    RewriteRule ^([a-zA-Z]+)/? $1.php [L,NC]
    I hope this is what you are after
    :. Web Design & Development Web Design Ireland
    :. Search Engines Optimization Search Engines Optimization
    :. Car Parts & Accessories Car Parts
    :. Cars Ireland Cars Ireland
    :. I Have 2 Find It Directory SEF Directory

Page 1 of 2 12 LastLast

Similar Threads

  1. Classified Script with mod_rewrite?
    By blacknight in forum CMS and Content Management
    Replies: 3
    Last Post: 25-07-2011, 07:28 AM
  2. mod_rewrite
    By ziycon in forum Coding Help
    Replies: 18
    Last Post: 17-02-2007, 04:50 AM
  3. Using mod_rewrite on subdomains?
    By dude in forum Server / Technical Administration Tips and Queries
    Replies: 5
    Last Post: 14-09-2006, 10:51 AM
  4. Apache Mod_rewrite - seo and more!
    By blacknight in forum Server / Technical Administration Tips and Queries
    Replies: 8
    Last Post: 07-08-2006, 12:00 PM
  5. Redirecting your old domain using mod_rewrite
    By blacknight in forum Server / Technical Administration Tips and Queries
    Replies: 1
    Last Post: 01-02-2006, 01:47 AM

Visitors found this page by searching for:

all rewrite rules show index.php iis blacknight

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •