0

Few days back I had posted a question related to this and I got some great push. Also I did some experimenting and research and achieved some good result. here is what exactly I have achieved. I put this in my .htaccess in my folder -'folder':

RewriteEngine On

#Look for the word "post" and take everything after "post" and store it in $1
RewriteRule   post(.+)$   something.php?file=$1   [L]

# allow public pages
RewriteRule ^index.php$ - [L]
RewriteRule ^style.css$ - [L]
RewriteRule ^bg.png$ - [L]
RewriteRule ^cat_bgg.gif$ - [L]
RewriteRule ^cat_bgr.png$ - [L]
RewriteRule ^h1_bg.gif$ - [L]
RewriteRule ^hd_bg.png$ - [L]
RewriteRule ^menu_bg.png$ - [L]

# serve everyone from specific-domain or specific-user-agent
RewriteCond %{HTTP_REFERER} ^http?://www.abc.com [OR]
RewriteCond %{HTTP_USER_AGENT} ^specific-user-agent$
RewriteRule ^ - [L]

# everybody else receives a forbidden
RewriteRule ^ - [F]

ErrorDocument 403 /index.php

So this is how it is working now: I put a link on:

www.abc.com

as

www.xyz.com/folder/post(somecode)

When someone clicks this link, as per .htaccess 'somecode' is taken and stored in $1 and processes:

www.xyz.com/folder/something.php?file=$1

and displays this content. But the url shown in browser is:

www.xyz.com/folder/post(somecode).

Now this is what I want to do. Instead of displaying:

www.xyz.com/folder/post(somecode)

can i show something nice like

www.xyz.com/somethingnice

or

www.xyz.com/folder/someword

How do I do this? Should I add something after the line RewriteRule post(.+)$ something.php?file=$1 [L]

Or is there some other method?

  • I don't understand, do you expect .htaccess to randomize your posts? It can't do that. You'll need to create another php page `somthingRandom.php` and then add another rule to `RewriteRule randompost$ somethingRandom.php [L]` Or you can modify your `something.php` so that when it does not receive a `file` parameter, it retrieves a random post and then just add another rule: `RewriteRule randompost$ something.php [L]` – Victor Levin Oct 05 '15 at 20:03
  • @Zealander No. I just said that the content seen will be of www.xyz.com/folder/post(somecode) but url in the address bar should be something nice and simple like www.xyz.com/randompost or www.xyz.com/folder/toppost or even www.xyz.com/somethinggood – Prince Gift Oct 05 '15 at 20:12
  • Why not just make the link `www.xyz.com/(somecode)` to begin with that is rewritten? – Panama Jack Oct 05 '15 at 21:21
  • @Panama-Jack Because the files, and even the .htaccess is in the 'folder' only. I didnt put them in the root. – Prince Gift Oct 05 '15 at 23:12

0 Answers0