Canonical url htaccess - .htaccess

I am trying to achieve certain thing via htaccess file.
I would like this
http://mypage.com/e-store/561/
http://mypage.com/e-store/562/
to look like this
http://mypage.com/tv-screens
http://mypage.com/computers
I have read that it is possible via htaccess with rewrite urls. But I cant manage to wrap my head around it.

Use this is .htaccess file:
RewriteRule ^([-a-zA-Z0-9_]+)/$ ?url=$1 [L]
And add in your code output pages as:
http://mypage.com/?url=tv-screens
Where on the parameter URL the necessary page is displayed.
This link doesn't display page screen name:
http://mypage.com/e-store/561/

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]

.htaccess rewrite url that has already been changed

I am upgrading my site which involves new scripts and a different URL
structure. There are currently a few thousand pages so I want to
basically move them in to a subdirectory so that they are not lost.
I am not very confident with htaccess so can someone please confirm that
the first part I have done is correct:
Old URL: http://www.example.com/article/another-dir/page-group/whatever.html
RewriteRule ^article/?$ http://www.example.com/archive/ [R=301,NC,L]
To achieve this: http://www.example.com/archive/another-dir/page-group/whatever.html
Search engines will see the above as a permanent move and in the address bar
it will show the new url. Is this right?
The second part is on the new script - the url's could be improved but I am
unable to change all the script so thought about using htaccess again but am
not sure if it can be achieved like this.
At the moment the url looks like this:
url: http://www.example.com/category/4/categoryname
In the htaccess the current rewrite rule for this type of url looks like this:
RewriteRule ^category/(.*)/(.*)$ category.php?id=$1&slug=$2
Is it possible to change this so that in the url address bar I end up
with this:
http://www.example.com/categoryname
Basically I don't want to see either the number or category/ in the resulting
url as it will be easier for visitors to use - is that possible??
Thanks in advance for any help.
The second question related to passing in URI components for querystring redirect and then hiding those components in the URL I don't think would be easy, if even possible, using RewriteRules.
For the first question though. Given the sample URLs you mentioned, the RewriteRule would need to include capture and backreference if you want to preserve the full URL in the redirection. For example:
RewriteRule ^article/?(.*)$ http://www.example.com/archive/$1 [R=301,NC,L]

RewriteRule from download.php?token=something into /download/something

I am working on url, I try htaccess, php, javascript and many other things but unable to figure it out.
My url is :
example/cheap-flight-to.php?country=lagos
and I want to change the url something like this :
example/cheap-flight-to.lagos
or
example/cheap-flight-to/lagos
please help me
The following should allow you to generate your urls in the format that you wish.
RewriteEngine On
RewriteBase /
RewriteRule ^example/cheap-flight-to/([a-zA-Z]+)$ /example/cheap-flight-to.php?country=$1 [NC,L]
What you want could be done using regular expressions in .htaccess, but it makes no sence, since it wouldn't be pointing to anything, unless you have a directory cheap-flight-to/lago in which you have an index.php that will show-up in the browser or return data. This means you have to setup a directory for each destination you want to go to. Is that really what you want? Usually it's been used the otherway around. The user (or a script for that matter) enters a url like "example/cheap-flight-to/lagos". Then through regular expressions in .htaccess you rewrite the url to "example/cheap-flight-to.php?country=lagos".
Have a look at http://httpd.apache.org/docs/1.3/misc/rewriteguide.html and
http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html for more on rewriting rules in .htaccess.

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

Resources