I have this following url localhost/test/index.php?page=1 And i want it to be
'index.php/page/1'
so far I have this :
RewriteEngine On
RewriteRule ^page/([0-9]+)/?$ index.php?page=$1 [NC,L]
But it's not working .Any suggestion what am i doing wrong ?
Try with this
RewriteRule ^page/([^/]*)$ index.php/?page=$1 [L]
If you set it correct then URL like this http://localhost/test/page/1 should work
Try this one
RewriteEngine on
RewriteRule ^(.*)/page/([0-9]+)$ /index.php?page=$2 [NC,L]
The url will be
localhost/test/index.php/page/123
If you want the url looks like
localhost/test/index.php/page/123/
change you rule into this one
RewriteEngine on
RewriteRule ^(.*)/page/([0-9]+)/$ /index.php?page=$2 [NC,L]
RewriteRule ^index.php\/page\/(.*?)\/?$ index.php?page=$1 [NC]
The above code should solve your probleem. But you may want to read up on mod_url_rewrite
See https://www.sitepoint.com/guide-url-rewriting for more info
Related
I have a working RewriteRule that rewrites any page to the literal url:
RewriteRule ^(.+)$ index.php?page=$1 [QSA,L]
The problem is I want to add page=$1&category=$2 and convert it to...obviously... /category/page
I tried this, but it doesn't seem to work:
RewriteRule ^([^/]+)/([^/]+)$ index.php?page=$1&category=$2 [QSA,L]
I should note that I would still like to be able to access pages without categories - ie /login or /about that should go to index.php?page=about for instance
Your solution will be as below.
RewriteRule ^([0-9a-zA-Z_\-]+)/([0-9a-zA-Z_\-]+)$ index.php?page=$1&category=$2 [NC,L]
Input url : http://www.test.com/my-cat/my-page
and it will be treated as : http://www.test.com/index.php?page=my-cat&category=my-page
Try with below, we are instructing apache to don't look for directory or file.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)$ index.php?page=$1&category=$2 [QSA,L]
try this
#https://www.example.com/index.php?category=9&page=CBSE `#https://www.example.com/category/page/CBSE`
Method One:
#use this code for generate new url
RewriteRule ^index/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)$ index.php?category=$1&page=$2 [NC,L]
Method Two :
RewriteRule ^index/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)$ index.php?category=$1&page=$2
Note :Hit Your Url index.php?category=$1&page=$2 to convert $i & $2 Create Dynamic Url Your Id Bases
This will work for you.
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /index.php?category=$1&page=$2 [L]
If you want to generate rewrite urls easily, there are a lot online rewrite url generators.
Thanks for all the contributions...
Because I needed to cater for both /page and /category/page...I ended up doing this:
RewriteRule ^([0-9a-zA-Z_\-][^/]+)$ index.php?page=$1 [N]
RewriteRule ^([0-9a-zA-Z_\-]+)/([0-9a-zA-Z_\-]+)$ index.php?category=$1&page=$2 [L]
But that was only half the solution as I needed to modify my PHP to check whether category is set or not and to send a 404 if it doesn't match. Otherwise /invalid_category/valid_pagewould still work.
The ideas above all pushed me in the right direction, thanks.
I have a problem with a rewriterule in my .htaccess, I would like to redirect like this:
www.mywebsite.com/category?p=2
to
www.mywebsite.com/category
where category is variable.
I have my rewrite engine on and other redirects are working fine. This is what what I got so far:
RewriteRule ^/([a-z_\/]*)\?? /$1 [R=301,L]
What is the best way to accomplish this?
Your request looks strange, but anyway, this should do it:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^p=
RewriteRule /?([a-zA-Z0-9]+)/? /$1? [R=301,L]
Use this:
RewriteEngine On
RewriteRule ^category$ /category?p=2 [L]
It will give you the following URL:
www.mywebsite.com/category
I want to get page no from url
Eg:
www.example.com/education/tutorial/php-234.html
to
PageNo=234
and
www.example.com/course-1504.html
to
PageNo=1504
I am using the following code in .htaccess
RewriteEngine on
RewriteRule ^([0-9]+).html$ Pages.php?PageNo=$1 [NC,L]
But it is not working
If we use
RewriteRule ([0-9]+).html$ Pages.php?PageNo=$1 [NC,L]
I got page no, But
RewriteRule ^([a-zA-Z0-9-]+).html$ Pages.php?PageName=$1 [NC,L]
is not working
Any suggestion for both combination
try:
RewriteEngine on
RewriteRule ^(.*)-([0-9]+)\.html$ Pages.php?PageName=$1&PageNo=$2 [L,QSA]
I am trying to redirect www.mysite.com/movie/name to www.mysite.com/movie/?url=name
for this I have added htaccess in movie/ folder, the code I have added is below:
RewriteEngine On
RewriteBase /movie/
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+).html$ index.php?id=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?id=$1
I am unable to redirect it, could anybody suggest me the right way to accomplish this?
Just a small change and it should work..
Try below code and let me know whether it worked for you or not..
RewriteEngine On
RewriteRule ^([a-zA-Z0-9-/]+).html$ index.php?id=$1
RewriteRule ^([a-zA-Z0-9-/]+).html/$ index.php?id=$1
Hope it helps...
First off, you only need to write command RewriteEngine On once.
Besides, replace last rule for
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?id=$1
The fault was in the last backslash.
I have a website that on one specific page it requires an extra variable.
At the moment, the htaccess I am using is:
RewriteEngine On
RewriteRule ^([^/]*)/$ /index.php?page=$1 [L]
Which works fine with one variable.
How would I get it to work with :
http://tessite.com/index.php?page=test&id=1
So it looked like:
http://tessite.com/test/1
Thanks for any help or replies.
It can be coded like this:
RewriteRule ^([^/]*)/([^/]*)/$ index.php?page=$1&id=$2 [L]
RewriteEngine On
RewriteRule ^(.*)/(.*)/$ /index.php?page=$1&id=$2 [L]
RewriteRule ^(.*)/$ /index.php?page=$1 [L]
Just add $2!
Also, [^/] isn't required, you can simply use ..