Htaccess issue with redirection? - php

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.

Related

How to get proper url rewriting with proper format in localhost?

My .htaccess file as below,
DirectoryIndex routing.php
RewriteEngine on
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+Milan_Practice/Milan_Mvc/routing\.php[\s?] [NC]
RewriteRule ^ Milan_Practice/Milan_Mvc/ [L,R=302]
RewriteRule ^Milan_Mvc/?$ Milan_Mvc/routing.php [L,NC]
By Appling above code I got url like below,
http://localhost/Milan_Practice/Milan_Mvc/?name=about
in above,there after "?",data is not in valid format as I want like this,
http://localhost/Milan_Practice/Milan_Mvc/about/
So please give your suggestion with proper ReWriting Rule for above code
ThankYou in Advance !!!
RewriteRule ^([a-z]{2,2})/([a-zA-Z0-9_-]+)$ index.php?name=$1 [QSA]
See http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html

.htaccess URL rewriting not working on pagination?

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

URL rewriting through .htaccess is not working properly

I have a .htaccess which reads as follows
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^([a-z0-9\-]+) /index.php?page_name=$1 [L]
I want the link
http://www.solublesilicates.com/our-services when clicked should read as http://www.solublesilicates.com/?page_name=our-services.
Please do help.
RewriteRule ^([a-z0-9\-]+)$ /index.php?page_name=$1 [L, QSA]
Just change it to the above. Should work perfectly.
You have error in your syntax. Your regex should end with $ sign
RewriteRule ^([a-z0-9\-]+)$ /index.php?page_name=$1 [L]
Change the Rewrite Rule to
RewriteRule ^([A-Za-z0-9\-]+) index.php?page_name=$1 [L,QSA]

How to rewrite URL in .htaccess, whats wrong here

think the user enter
localhost/app/public/anything/anything/index/php/id/5
then id like to change it to the
localhost/app/public/index.php?id=5
the expression that i wrote is this
RewriteRule ^index/php/id/([0-9]+)$ http://localhost/saecms/public/index.php?id=$1 [L]
but it doesn't work, whats wrong here? thank you
You can use this rule in your /app/public/.htaccess file:
RewriteEngine On
RewriteBase /app/public/
RewriteRule (?:^|/)index.php/id/(\d+)/?$ index.php?id=$1 [L,QSA,NC]

Using mod rewrite to clean my URLs

I know this question may have been asked many times before and I may be down-voted a lot but trust me, this was my last resort after testing and reading many articles on google.
I have the url /index.php?action=gametypes&mode=control-point which I would like to rewrite to /gametypes/control-point.
I've tried
RewriteEngine On
RewriteRule ^gametypes/([^/\.]+)/?$ index.php?action=gametypes&mode=$1[L]
Now when I visit /gametypes/control-point I get a 404 not found and the URL shows rewrites to localhost/thecoremc/gametypes/control-point/index.php. It's a 404 because there is no index.php. Any idea what I could use to successfully load the page?
Extra info: I'm running my localhost with the domain localhost/thecoremc/ and apache 2.4.4
Thanks!
You could try this instead...
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)\.html$ /index.php?action=$1&mode=$2 [L]
I used a dummy-domain, which was http://www.domain.com/index.php?action=gametypes&mode=control-point to achieve this.
Based on your comment, try this...
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)\.html$ /thecoremc/index.php?action=$1&mode=$2 [L]
which is based on: http://localhost/thecoremc/index.php?action=gametypes&mode=control-point
You can use this code in your /thecoremc/.htaccess file:
RewriteEngine On
RewriteBase /thecoremc/
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?action=$1&mode=$2 [L,QSA]
Try this. This might be helpful for your work.
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^id=(.*)&name=(.*)$
RewriteRule ^articles\.php$ /article/%1/%2? [R=301]
RewriteRule ^article/([^-]+)/([^-]+)$ /articles.php?article_id=$1&article_name=$2 [L]
The above code will redirect
localhost/a1/articles.php?id=10&name=xyz
to
localhost/article/10/xyz
Try this:
Options +FollowSymLinks
RewriteEngine on
RewriteRule gametypes/(.*)/(.*)/ index.php?action=$1&mode=$2

Categories