mandude Posted March 3, 2012 Share Posted March 3, 2012 Not sure if that title encapsulates what I am trying to say, but basically I have the script that can work if the page is on the root of the domain with htaccess, but not in a subfolder. I just want an easy way to have it so if I type in a domain name such as: www.mysite.com/subfolder/hi that it will put "hi" in the page where I want. The code I had was something like: $item = $_GET['item']; if (!$item) $item = "test"; $item2 = str_replace("-", " ", $item); then in the page it would have <?=$item2;?> but I cant get it to work. help please! Quote Link to comment https://forums.phpfreaks.com/topic/258213-adding-predefined-text-to-webpage/ Share on other sites More sharing options...
dannyb785 Posted March 3, 2012 Share Posted March 3, 2012 When you say what you tried hasn't worked, what have you tried? You didn't mention anything about htaccess, which is what would solve this problem, since it is relating a special url with what is displayed on the page. You would put this code in your htaccess file. This code probably isn't exact, but it's the right idea RewriteEngine On RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ specialpage.php?variable=$2 [NC] Quote Link to comment https://forums.phpfreaks.com/topic/258213-adding-predefined-text-to-webpage/#findComment-1323599 Share on other sites More sharing options...
mandude Posted March 4, 2012 Author Share Posted March 4, 2012 I don't know php at all. Someone helped me with what I have so far. Just to clarify, is there anything I need to change in that htaccess you just wrote, like specialpage.php to the subfolder or index.php thanks Quote Link to comment https://forums.phpfreaks.com/topic/258213-adding-predefined-text-to-webpage/#findComment-1323813 Share on other sites More sharing options...
S3cr3t Posted March 4, 2012 Share Posted March 4, 2012 Change specialpage.php to your *.php file. Change ?variable=$2 to ?item=$2 Quote Link to comment https://forums.phpfreaks.com/topic/258213-adding-predefined-text-to-webpage/#findComment-1323816 Share on other sites More sharing options...
mandude Posted March 4, 2012 Author Share Posted March 4, 2012 Just tried it, it did not work. will just say URL not found. Here is the htaccess file I had: Options +FollowSymLinks +Indexes RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^.]+)/([^.]+)$ index.php?item=$1&query=$2 [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^.]+)$ index.php?item=$1 [L] # AddHandler application/x-httpd-php .php .htm .html RewriteEngine on # RewriteBase /offers RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^.*$ - [s=44] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [s=44] RewriteRule ^(.*)$ index.php?k=$1&%{QUERY_STRING} Quote Link to comment https://forums.phpfreaks.com/topic/258213-adding-predefined-text-to-webpage/#findComment-1323845 Share on other sites More sharing options...
mandude Posted March 4, 2012 Author Share Posted March 4, 2012 Ok so like I said I dont know squat about coding. But I can see that if I put something like www.mysite.com/subfolder/index.php?item=something that "something" will be replaced in the document because item was defined (and in the index.php it tells it to replace item with item2 which is in the document) So I just have to figure out how to make the site know that anything after the /subfolder/ is the item. so mysite.com/subfolder/something that "something" is the item. Maybe that makes things clearer (maybe you already knew that) but I am not good with .htaccess files thanks again Quote Link to comment https://forums.phpfreaks.com/topic/258213-adding-predefined-text-to-webpage/#findComment-1323853 Share on other sites More sharing options...
mandude Posted March 4, 2012 Author Share Posted March 4, 2012 I figured it out! So I put this in the htaccess Options +FollowSymLinks +Indexes RewriteEngine on RewriteBase /offers RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^]+)/([^]+)$ index.php?item=$1&query=$2 [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^.]+)$ index.php?item=$1 [L] # AddHandler application/x-httpd-php .php .htm .html subdomain was offers. I put that in that subdirectory (seems weird that I defined the directory but still had to put it in the directory) and now it works can be locked. this thread may be useful for others later Quote Link to comment https://forums.phpfreaks.com/topic/258213-adding-predefined-text-to-webpage/#findComment-1323858 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.