Jump to content

[SOLVED] A little help needed


phpknight

Recommended Posts

I am new to mod_rewrite.  Because of cPanel overwriting the httpd.conf file, I have to use .htaccess.  It just seems like the rules do not work for me as planned.  If somebody can help me figure these first few out, I will probably be able to start making progress. 

 

Two examples

Example 1

  This is a simple version of what I ultimately need to do, but I do not need you to solve it.  I just need help getting started.

 

  Rule: (.*) getshop.php?shop=$1

  What I expect: I think it should work like this: somebody goes to www.myshop.com/bobstore -- it redirects to www.myshop.com/getshop.php?    shop=bobstore.  So, if I var_dump the $_GET, it should be shop=bobstore.

  What it does:  $_GET dumps shop=getshop.php no matter what goes in place of bobstore.  I tried putting NS and some other rules, but nothing helps.  It seems to give me the value AFTER the redirect, not before. 

 

Example 2

  Rule: [:alnum:]* getshop.php 

  What I expect: www.myshop.com/sldk23949  redirects to getshop.php

  What it does: redirects even www.myshop.com/#($(/1233/*@#*KKdl23 to getshop.php

 

I have tried to use ^ and other things, but nothing behaves as I thought it would.  Therefore, if somebody can start me off or even write a simple rule and rewrite that I could try (such as redirecting something with three digits to a certain page), that would be great.

Link to comment
Share on other sites

I'm not sure what rule you're going to write, so I will just give an example how to use it with $_GET, turning a dynamic url to a static url.

 

Example of dynamic url:

http://domain.tld/news.php?articleid=155644

Example of static url:

http://domain.tld/article/155644

 

The rule will look like this,

RewriteEngine on
RewriteRule ^article/([0-9]+)$ news.php?article=$1

 

^ - start of the url

([0-9]+) - the regex, combination of number from 0 to 9

$ - end of the url

$1 - just simple means the value from the regex

 

Hope this helps.

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.