Rewriting different URL from one page to another using .htaccess - .htaccess

I need to know if there is a way to redirect long URLs to short URLs.
I have an RSS page that will list out a number of news items from my website. The URL format of each item (as per MySQL query) is something like http://example.com/news.php?id=2.
On my news.php (after being redirected to the news page upon clicking on any news title on the RSS page), there are parameters set to carry along the IDs which looks like http://example.com/news.php?news=2&view=1&topic=12.
For SEO purpose, I need to erase that dirty query string so that viewers will only see http://example.com/news.php?id=2 while on the server-side, it actually reads http://example.com/news.php?news=2&view=1&topic=12.
I had created an .htaccess file and it is placed inside the rss folder (where the rss.php file is located ) and tried several attempts but to no available.
Help me on this.

Here's what I would do:
RewriteEngine on
# id + view + topic
# http://www.domain.com/news/1/1/12 will load: /news.php?news=1&view=1&topic=12
RewriteRule ^news/([0-9]+)/([0-9]+)/([0-9]+)(/?)$ /news.php?news=$1&view=$2&topic=$3 [QSA,L,NC]
Please this .htaccess in the root folder.

Should the parameters be assigned to ($1,$2,$3...etc) instead?
RewriteRule ^news(/?)$ /news.php?news=$1&view=$2&topic=$3 [QSA,L,NC]

Related

htaccess - get content on one url from another url

Is there the opportunity to get content on one url from another url? like this:
test.com/dir1 shows content from query test.com/getinfo/index.php?q=dir1
or
test.com/dir2 shows content from query test.com/getinfo.php?q=dir2
I need that because i must do 50 urls like test.com/dir1 ../dir50 which has the same template but with some different content based on query and one virtual url with query is better than 50 real directories.
I tried do but couldnt! Thanks in advance!
If it is all on the same host, then have a look at mod_rewrite, which can do amazing things. Just make sure you read the manual through, as there are a lot of details to take in.
RewriteEngine On
RewriteRule ^/dir1$ /getinfo/index.php?q=dir1 [L]
or more generically:
RewriteEngine On
RewriteRule ^/dir(.*)$ /getinfo/index.php?q=dir$1 [L]

links includes coma and hash htaccess

I'm using links like that:
find.php?id=1&n=2#loc
I want to my links look like:
but i dont know how to change htaccess and when/where use # to link some place in the page #loc
htaccess:
RewriteRule ^(.*),(.*),(.*)$ $3.php?id=$2&n=$1 [L,NC,NS,NE]
Help lease
The #loc part of the URL is never sent to the server, so there's no way for you to match against it in your htaccess file. Anything starting from the # in the URL is called a fragment and it's used by the browser, the server doesn't know it's even there.

.htaccess redirect question

I have a slight problem with .htaccess redirect.
I have a dynamic site with 2 levels of variables - content="type -(alpha)" and ID="number" but this is very not seo friendly what I really would like to create is a rewrite rule that generates a "friendly" url for serach engines & users alike. Very much like WordPress does.
Each ID is already unique (obviously) and on creation is creating a unique "permalink" field so for example ID=1 has a "permalink field" as "2009/10/27/page title" and ID=100 would be "2010/10/27 page title".
I would like folder/wall.php?content=type&ID=number to redirect to folder/permalink.php/html/htm (don't mind a non dynamic extension)
Any clues? - this is not right (I know) but it also "breaks" my css file
RewriteEngine On
RewriteRule wall/content/(.*)/ID/(.*)/ wall.php?content=$1&ID=$2
RewriteRule wall/content/(.*)/ID/(.*) wall.php?content=$1&ID=$2
You need to make sure you have a URL convention that won't conflict with other files on the server. For example, if your page is displaying "Products" and you don't have an actual folder in the root of your server called /products/, you could do this
RewriteEngine On
RewriteRule ^products/([^/\.]+)/([^/\.]+)/?$ wall.php?content=$1&id=$2 [L,NC,QSA]
Replace "products" in this example with whatever name is most appropriate for what your wall.php page does.
This would equate to the following URL
www.yoursite.com/products/title/29/
Which would rewrite to
www.yoursite.com/wall.php?content=title&id=29

.htaccess ModREwrite

This is a totally new area for me so please be patient. I want to create "permalinks" for a dynamic site I am working on. At the moment all the pages (not the index) are referenced using an ID variable thus:
http://www.domainname.com/page.php?ID=122 (etc)
I want to create a suitable rewrite rule so that a useable URL would be more like this:
http://www.domainname.com/page/'pagetitle'.html (could be .php doen't matter)
Page title is stored in the database and obviously is linked directly to the ID
Am I right in thinking thr rewrite rule would be something like this?
RewriteCond %{QUERY_STRING} ^(([^&]*&)*)ID=([^&]+)(&+(.*))?$
RewriteRule ^page\.php$ /page/%3?%1%5 [L,R=301]
My ideal would be to just create
http://www.domainname.com/'pagetitle'.html
But have absolutly no idea how to do that.
Now the other question/sub question.
If the rewrite works i.e. you type in http://www.domainname.com/page/'pagetitle'.html to a browser address bar does the htaccess file work "the other way" in accessing the page http://www.domainname.com/page.php?ID=122 or do I have to create a function to take the 'pagetitle'.html bit of the URL and convert it to page.php?ID=122 ?
Also, sorry, but this is all new; if I create a site map (xml or php etc) using http://www.domainname.com/page/'pagetitle'.html will the SE spiders go to http://www.domainname.com/page.php?ID=122? or di I need to create the sitemap using the ID variables?
Question 1 and 2:
The condition is not required in this case. Use it like this:
RewriteRule ^/page/([\w-]+).html$ /page.php?title=$1 [L,R=301]
This transforms
/page/blabla.html to /page.php?title=blabla
You need to find the right page using the title parameter in page.php
Question 3:
I suggest you never use the querystring variant of the urls in any of your anchor links or xml sitemap. This way the spiders will only know of the friendly urls.

Redirect Dynamic Page to Dynamic Page In Different Folder

My current page is set up like this, where '#' is a number for each user;
http://site.com/member.php?u=#
I want to move it to a different folder on the same site, how would I set up .htacces so when some goes to the page above, they're automatically redirected to this;
http://site.com/new_folder/member.php?u=#
I have seen a few tutorials that show you how to move say member.php?u=234 to /new_folder/member.php?u-234 - But of course new members are registering all the time and even if they weren't I don't want to have to do that for about 1700 users.
Any help would be appreciated.
It should be as follows:
RewriteBase /
RewriteRule ^member\.php$ new_folder/member.php [NC,R=301,L]
And the initial query string will be automatically appended to the destinaion URL.

Resources