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
Related
I have created the website like WOWcrush http://phone77.ml I want the url be like phone77.ml/Naveen in title it should have my name but there come ? at the last of the URl like http://phone77.ml/?Naveen only if use ? it works fine or it shows 404 error please help
You will need to use the .htaccess file in order to point /Naveen to the coresponding get var.
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^([^/.]*)/?$ index.php?section=$1 [L]
or you can be more specific like this
RewriteRule ^/Naveen$ index.php?section=Naveen [L]
$_GET['section'] will contain Naveen and you can use that in your code to show the correct view
By default everything what goes after the '?' symbol is parameters in url. It can be changed, but for that is necessary to properly configure a web server (e.g. Apache or Nginx).
Also can be necessare to made some changes in code or/and configuration of your application.
You can see the question mark as a 'where'. So what you are saying is;
http://phone77.ml/ 'WHERE' Naveen. It all depends on how you build your site, but apparently you have a clause looking for Naveen in the URL. Maybe something like; if(isset($_GET['Naveen'])){...}.
You could also have separate documents for each you pages, then you would link to to that document instead and the URL would look like http://phone77.ml/Naveen.php f.ex.
You might also be interested in looking up the .htaccess document https://httpd.apache.org/docs/current/howto/htaccess.html where you can manipulate the URL from.
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'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
I'm into rewriting a url in different ways. I mean I want to know how to use mod_rewrite so I can do the following:
1- convert a .php to html for a speific url
i.e: from www.mydomain.com/news.php to www.mydomain.com/news.html
I found some interesting codes, but not sure which one works without any errors...
some of what I found:
RewriteEngine on
RewriteRule ^(\d+)/(\w+).html$ index.php?id=$1&title=$2
2- convert any sub url of that news.php file to
news.php?do=news&id=24455
so the topics or threads show like this without slashes /
I find the 2nd question a lot difficult, but sure there must be a solution for that.
any idea how to get both questions done for a specific url like what I stated above...!!
Thanks
convert a .php to html for a speific url i.e: from www.mydomain.com/news.php to www.mydomain.com/news.html
RewriteRule ^news\.html$ /news.php
Guess for the second (assuming you want to rewrite /news/foo.html urls):
RewriteRule ^news/(.*)\.html$ /news.php?id=$1
I am currently coding a pagination script into many parts of my site, this has been a well needed and requested feature and I have finally been able to come round and start coding it, it is all going well, until I find that my rewritten urls don't like working with the pagination urls.
So, an example page on my site would be news.php. This file structure can be something like news.php?id=5. I have rewritten the url like so:
/news/5/
## Rewrite URL's for News & Dev ##
RewriteRule ^news/([0-9]+)/$ /news.php?id=$1 [L]
RewriteRule ^news/([0-9]+)$ /news.php?id=$1 [L]
RewriteRule ^news$ /news.php [L]
RewriteRule ^news/$ /news.php [L]
The pagination script I am using prepends two new variables in the url, the new url turns out to be this:
news.php?page=1&ipp=55id=5
I would really appreciate it if anyone could assist me in making the urls look better, as it defeats the object of having it in the first place if after they use the pagination, it changes the url back to a clunky and ugly url.
I don't want it to be required to have parts of the url, that is something I really don't want..
e.g I don't want the url to be required to be /news/1/55/5, instead id like it to be optional.
Thank you for your time, it is appreciated!
Additional Information
The links in my news script currently display like so:
news.php?page=1&ipp=55id=5
I don't like to see ugly urls like that, and want to make the url look better using mod_rewrite, It would be better if the urls would display like so:
/news/PAGE/IPP/ID/ -> return news.php?page=1&ipp=55id=5
Also, to make it as user friendly as possible, I don't want any of the fields to be required as such, so for example I would like to have the following link accessible at all times without it requiring the other fields.
/news/ID/
Then, when the user clicks a pagination link, it would use the following link structure:
/news/PAGE/IPP/ID/ -> return news.php?page=1&ipp=55id=5
This is all from user feedback of my site, and is something that people have been asking for. Problem is, I don't understand even simple .htaccess
Thanks
RewriteBase /
# add slash to end of url if not present (and do a redirect)
RewriteCond $0 !/$
RewriteRule ^news([^\.]*)$ $0/ [L,R=302]
# rewrite url with format /news/[<id>/[<page>/[<ipp>/]]]
RewriteRule ^news/(?:([0-9]+)/)?(?:([0-9]+)/)?(?:([0-9]+)/)?$ /news.php?id=$1&page=$2&ipp=$3 [L]
Not sure what ipp is supposed to be, but my guess is it shows the number of item per page. I would personally not like to have that in my url.
You can have :
news/id/page/ipp with
RewriteRule ^news(/?)$ news.php [L]
RewriteRule ^news/([0-9]+)-(.*)_([0-9]+)(/?)$ news.php?page=$1&ipp=$2&id=$3 [L]
news/1222-subjet-for-example_34
return :
news.php?page=1222&ipp=subject-for-example&id=34
use (/?) instead of create many rules ;)
Hope it's works for you.