I've made my own blog on my domain and for displaying the articles I'm using a dynamic URL to display the article content on the page.
An example how it looks now:
http://www.blog.madetocreate.nl/artikel.php?id=47
Now I've searched for a mod_rewrite method for days, but everything I tried fails. The service provider told me mod_rewrite is enabled and I only have to access it with a .htaccess file.
The file I have at this moment contains the following code:
RewriteEngine on
RewriteRule ^artikel/([^/]+)/?$ artikel.php?id=$1 [L]
I want to get the url to look like this:
http://www.blog.madetocreate.nl/artikel/47/title-of-the-post-here/
But so far I can't even get managed to get the first "artikel/47/"
Any idea on what I'm doing wrong?
Thanks!
The regex should look like the following:
^artikel/([0-9]+)/([\w-]*)$
Which gives you:
RewriteEngine on
RewriteRule ^artikel/([0-9]+)/([\w-]*)$ artikel.php?id=$1 [L]
([0-9]+) matches 1 or more number
([\w-]*) matches 0 or more word character and -, meaning that you can have both artikel/47/ and artikel/47/title-of-the-post-here
Related
I am trying to use a redirect to the same page but with a query string.
RewriteRule ^fixtures(.*)$ views/fixtures.php
RewriteRule ^fixtures/(.*).([a-zA-Z_-]*) views/fixtures.php?date=$1
When I click any links from the page, nothing happens. In chrome debugger it cancels the request.
Any idea what I am doing wrong?
Cheers
It would be great to see a working example but just looking at your rewrite rules it seems there might be a small issue with your regex.
The issue I can see is that your first line expects something like:
example.com/fixtures*absolutelyanythingeleseontheurl*
But I think this is being overidden by the next line which is capturing two sections of the url, anything after fixtures/ and anything after the fullpoint that is a-zA-Z, _ or -. But your initial .* has already taken care of that.
RewriteRule ^fixtures/(.*).([a-zA-Z_-]*) views/fixtures.php?date=$1
Have you tried something like this:
RewriteRule ^fixtures$ views/fixtures.php
RewriteRule ^fixtures/(.*) views/fixtures.php?date=$1
The above would do the following:
example.com/fixtures/ will resolve to views/fixtures.php
and the next line would resolve to the following:
e.g. example.com/fixtures/22-06-2014 to views/fixtures.php?date=22-06-2014
I am trying to change my long url to something short I did it successfully but after sending get info URL is not chanining to what I want like I search for something and it show my url like this
/search.php?q=a&limit=150&siz=any
so I want to convert it automatically in url bar like this
/car/150/any
I am using this
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /search.php?q=$1&limit=$2&siz=$3 [R,NC]
but it is not converting link automaticly however it works when I write in url like
/car/150/any
same related question is asked by someone here so I need something like that for my link
Search url automatically in mod_rewrite version
Any help would be appreciated. Thanks
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^search/([^_]+)/([0-9]+)/([^_]+).html$ search.php?act=$1&limit=$2&siz=$3 [L]
access url with
search/car/150/any
better put constant ^search as page identifier to avoiding conflict with other url rewrite,
([^_]+) can receive string input
([0-9]+) only can receive number input
I got this url
/localhost/andalucia/productdetails.php?value=20
I want to change it to
/localhost/andalucia/productdetails/20
how do you do this and how will you get the value 20 in the handler page?
should I change the coding or I just add an ht access file?
If it is adding a ht access file what code should be in it?
How if I have more pages like:
/localhost/andalucia/product
/localhost/andalucia/home
/localhost/andalucia/contactus
Will they be affected automatically too?
ok i tried to use
RewriteRule ^productdetails/([0-9]+)$ productdetails.php?value=$1 [L,QSA]
but now the problem is all my pictures is gone in the html and i cant open the other page like
/localhost/andalucia/product
/localhost/andalucia/home
/localhost/andalucia/contactus
i need a htaccess code that can open all of these
/localhost/andalucia/product
/localhost/andalucia/home
/localhost/andalucia/contactus
/localhost/andalucia/productdetails/20
pls helpp someone
With the apache extension mod_rewrite it is really easy to transform your pretty URLs into the URLs needed by your script. This .htaccess example which you place in your web root should get you going:
RewriteEngine On
RewriteRule ^andalucia/productdetails/([0-9]+)$ /andalucia/productdetails.php?value=$1 [L]
This example will only rewrite andalucia/productdetails/NNNN... format URLs, all other URLs won't be affected. If you need to pass other query parameters, like /andalucia/productdetails/20?sort=asc you need to pass the QSA flag (query string append) to the rewrite rule:
RewriteRule ^andalucia/productdetails/([0-9]+)$ /andalucia/productdetails.php?value=$1 [QSA,L]
The L flag will prohibit the evaluation of next rules. Just look up the mod_rewrite documentation for a in-depth discussion!
I want this url
http://www.test.racebooking.net/rankings/classifica.html
to point to
http://www.test.racebooking.net/rankings.php
thus, i wrote this rule in my .htaccess file
RewriteRule ^rankings\/[a-zA-Z0-9\-]+\.html$ /rankings.php
I really can't figure out why, when i type the first url, i get a 404 error msg.
RewriteEngine is on.
/rankings.php exists.
Moreover, I have another RewriteRule, much more complex, which i
wrote, which is working like charm.
classifica.html doesn't exist. I'm just updating my website with
more SEO friendly urls
What's wrong with my rule??
When i test the regexp in any online regexp tester it detects the string "rankings/classifica.html", this means the regexp actually corresponds, but nothing is working....
I found the error, but i didn't find out why it happens.
Basically, if pattern and substitution start with the same word, the RewriteRule doesn't work.
EXAMPLE
If i write this rule in .htaccess:
RewriteRule ^rankings\/[a-zA-Z0-9\-]+\.html$ /rankings.php
and type this URL
http://www.mywebsite.net/rankings/classifica.html
I get a 404 Error. Even if the Regexp is correct, the apache RewriteEngine is not working. Instead, if i write this rule:
RewriteRule ^ran-kings\/[a-zA-Z0-9\-]+\.html$ /rankings.php
and type this URL
http://www.mywebsite.net/ran-kings/classifica.html
Everything works fine.
I noticed on youtube their url does not have a file extension and querystring. I've been trying to emulate something similar but found I had to either include the file extension or a trailing slash.
members.php?agefrom=20&ageto=40&city=london (works)
members/?agefrom=20&ageto=40&city=london (works)
members?agefrom=20&ageto=40&city=london (doesnt work)
So I was just wondering how can I get the third case to work? i've tried a few things in the htaccess file.
RewriteRule ^members$ index.php?page=members&%{QUERY_STRING} [QSA,L]
I have tried the above but to no avail.
Any help would be appreciated.
The RewriteRule that you posted is correct for members.php? and for members? It should not work with members/
You must have additional RewriteRules before this one that are getting applied first and are affecting this rule.
However, here is a rule that should still work for you:
RewriteRule ^members/?$ index.php?page=members&%{QUERY_STRING} [QSA,L]
The /? is saying to match if the slash exists or if it doesn't exist.
Have you tried to remove the $ on the end?
RewriteRule ^members/?$ index.php?page=members&%{QUERY_STRING} [QSA,L]
This did work in the end, all I had to do was move it nearer the top of the htaccess file. I had the following line which I guess was being read instead.
....
RewriteCond %{REQUEST_URI} ^/members$ [OR]
....
I am changing my approach to SEO URL's because I was trying to find articles on how the googlebot actually crawls forms and how it prefers the GET method. I was using jquery to alter my action parameter to write the following URL:
/members/london/18-to-25
I dont know how much google likes jquery and whether it would scan javascript code. I am assuimg it just follows the HTML code and having done some research I have changed my form to use the GET method and so the bot can crawl my form without complaining so now my URL looks like this:
/members?location=london&agefrom=18&ageto=40
I am on the right track to assume this? or should I just stick with jquery to rewrite the action parameter for an seo friendly URL?