Jump to content

Understanding the basics.


YourNameHere

Recommended Posts

Hi,

 

I am trying to start learning mod rewrite. I have read several blogs and other articles about it. They all have assumed knowledge that I don't.

 

What I am wanting to achieve seems fairly simple.

 

My directory structure looks like this.

 

localhost/testServer/websiteName/

 

C:/xampp/htdocs/

    - testServer

          - websiteName

              - index.php

                .htaccess

 

I want the mod_rewrite to 'catch' urls from index.php and change them from index.php?tutorial=$1 to look like /websiteName/tutorial/$1

 

however, I have pasted the sample codes from different blogs in and it doesnt work at all.

so I guess I am asking for someone to take a look and find my issue. ( I know through phpinfo() that the module is active)

 

 

htaccess

<IfModule mod_rewrite.c>  
RewriteEngine on  
RewriteRule index.php/([a-z]+) /websiteName/index.php?tutorial=$1  
</IfModule>

 

I renamed the htaccess file to htaccess from .htaccess

Link to comment
Share on other sites

So yes, you do have it back to front, the way mod_rewrite would generally work is you would make all your links on your site the latter of those two, then mod_rewrite will convert it back to the 'ugly' URL. In theory you could perhaps mod_rewrite in both directions (but it means anybody viewing links on your page will view the 'ugly' format), but anything after the question mark is a query string and as such will not work with the RewriteRule in the manner your attempting, you'd have to use something more along the lines of RewriteCond %{QUERY_STRING}. But you'd be much better off switching the two over.

Link to comment
Share on other sites

...switching the two over.

 

Like so?

 

RewriteRule  /websiteName/index.php?tutorial=$1 index.php/([a-z]+)

 

Edit: Never-mind, that didn't work. I think I missed your point.

I tested it against this url:

 

http://localhost/testServer/Majesticlicks.com/index.php?tutorial=lightBursts

 

should look like:

http://localhost/testServer/Majesticlicks.com/tutorial/lightBursts

Link to comment
Share on other sites

You want all URLs to look like the second one right? So you need to make all URLs on your pages look like the second one. The RewriteRule is then used to rewrite all URLs of that format into the format the actual file is stored at.

 

RewriteRule /testServer/Majesticlicks.com/[^/]+/[^/]+ /testServer/Majesticlicks.com/index.php?$1=$2

 

Therefore you are taking the URL you WANT and rewriting it to the ACTUAL URL.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.