Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Location
    Velsen Noord, Netherlands
    Posts
    218
    Thanks
    6
    Thanked 0 Times in 0 Posts

    rewriterule on subdomain doesn't work

    I have tried several combinations (searched from google), but none are working, I also add "RewriteEngine on" to the .htaccess, just as my hosting company told me.

    I have this following url:

    Code:
    http://submain.domain/folder of url/index.php?page=$1
    $1 can stand for Home, about, contact

    The .htaccess code I use is this:
    Code:
    RewriteEngine on
    RewriteRule ^page/?$ http://submain.domain/folder of url/index.php?page=$1 [L]
    Nothing happends.
    But it needs to be:
    http://submain.domain/page/any of the mainpages


    Another thing is that I also have "depth" pages:
    Then the rewriten url needs to be:
    http://submain.domain/Offerte/offert...dracht/another item

    How can I do that?

  • #2
    Codeasaurus Rex
    Join Date
    Jun 2008
    Location
    Redmond, WA
    Posts
    660
    Thanks
    31
    Thanked 100 Times in 94 Posts
    Important Note: This fix is assuming your .htaccess is in the subdomain (ie: http://subdomain.domain/.htacess). If not, please clarify this.

    You appear to be invoking the regex improperly. Try something like this:

    Code:
    RewriteEngine on
    RewriteRule ^page/([A-Za-z]*)$ http://subdomain.domain/folder_of_url/index.php?page=$1 [L]
    This will cause all requests to:

    http://subdomain.domain/page/<insert alphabetic page>

    to query

    http://subdomain.domain/folder_of_url/index.php?page=<insert alphabetic page>

    Keep in mind that this ONLY covers alphabetical page names. If you include numbers or other characters it will have to be modified.

    (Bonus Tip: You may want to use the QSA flag as well ([L,QSA]) if you want to automatically append query strings (i.e: http://...../page/my_page?query=string))

    For more clarification on how this is done, check out this tutorial.
    Unless otherwise stated, any code posted is most likely untested and may contain syntax errors.
    My posts, comments, code, and suggestions reflect only my personal views.
    Web Portfolio and Code Snippets: http://shanechism.com

  • #3
    Regular Coder
    Join Date
    Jul 2007
    Location
    Velsen Noord, Netherlands
    Posts
    218
    Thanks
    6
    Thanked 0 Times in 0 Posts
    The .htaccess is in the root of the subdomain.

    I have tried, a couple of things you posted, even the tutorial but it didn't work.

    The address remain the dynamic address, instead of the more friendly url.

  • #4
    Codeasaurus Rex
    Join Date
    Jun 2008
    Location
    Redmond, WA
    Posts
    660
    Thanks
    31
    Thanked 100 Times in 94 Posts
    Your phasing suggests that you might be expecting a redirect instead of a rewrite. The rewrite engine basically translates the clean URL into the dynamic URL for the purposes of the server.

    Did you try navigating to the clean URL in your browser?
    Unless otherwise stated, any code posted is most likely untested and may contain syntax errors.
    My posts, comments, code, and suggestions reflect only my personal views.
    Web Portfolio and Code Snippets: http://shanechism.com

  • #5
    Regular Coder
    Join Date
    Jul 2007
    Location
    Velsen Noord, Netherlands
    Posts
    218
    Thanks
    6
    Thanked 0 Times in 0 Posts
    it's kinda working now, but the only thing, is that the url is now the friendly url, when I click on a menu item I get a message that the page isn't found, the url uses part of the friendly url but with the dynamic at the end.

    Do I need to change the menu urls as well, because the menu of the website (links) are not working.

  • #6
    Codeasaurus Rex
    Join Date
    Jun 2008
    Location
    Redmond, WA
    Posts
    660
    Thanks
    31
    Thanked 100 Times in 94 Posts
    Then, as I detailed more at the end of this post, you'll want to add the QSA flag.

    Change [L] to [L,QSA].
    Unless otherwise stated, any code posted is most likely untested and may contain syntax errors.
    My posts, comments, code, and suggestions reflect only my personal views.
    Web Portfolio and Code Snippets: http://shanechism.com

  • #7
    Regular Coder
    Join Date
    Jul 2007
    Location
    Velsen Noord, Netherlands
    Posts
    218
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by ShaneC View Post
    Then, as I detailed more at the end of this post, you'll want to add the QSA flag.

    Change [L] to [L,QSA].
    I already did that, but the menu holds the following as link (displaying only the Home item, but there are more):

    Code:
    <a href="index.php?page=Home">Home</a>
    I have seem a website that needs to change the menu href to => Home

    and in the .htaccess create a rule for this:

    Code:
    RewriteRule ^Home$ http://subdomain.domain/Gratisofferte.nu/index.php?page=Home [L,QSA]
    At the moment the cleanurl is as followed:

    http://subdomain.domain/folder/page/Home

    So when I click on a menu item (for example the home button), I get in the url:

    http://subdomain.domain/folder/page/index.php?page=Home

  • #8
    Codeasaurus Rex
    Join Date
    Jun 2008
    Location
    Redmond, WA
    Posts
    660
    Thanks
    31
    Thanked 100 Times in 94 Posts
    Well following the example we saw before you need to eliminate all of your dynamic URLs. Remember: Rewrite != Redirect.

    So, this link:

    Code:
    <a href="index.php?page=Home">Home</a>
    Needs to become this link:

    Code:
    <a href="page/Home">Home</a>
    Keep in mind, though that this will not work with the rewrite rule I discussed earlier:
    Code:
    http://subdomain.domain/folder/page/Home
    For that you'll need to modify ^page/([A-Za-z]*)$ to ^folder/page/([A-Za-z]*)$
    Unless otherwise stated, any code posted is most likely untested and may contain syntax errors.
    My posts, comments, code, and suggestions reflect only my personal views.
    Web Portfolio and Code Snippets: http://shanechism.com


  •  

    Posting Permissions

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