URL Rewriting in PHP With Parametres - php

I am using Wamp server that is localhost is my server and "mysite" is my site folder name in WWW direcotry
Here is my URL
..../mysite/videos/show.php?id=535&category=books
want this
......./mysite/videos/show/id/category
My .htacces code is:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^videos/show/(.*)/(.*)$ /videos/show.php?id=$1&category=$2
But it is not working any help...

I had the same problem 1 month ago. I found the answer thanks #anubhava. He`s suggestion work perfectly for me give it a try i hope to help you.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+videos/show\.php\?id=([^&\s]+)&category=([^&\s]+) [NC]
RewriteRule ^ /videos/show/%1/%2? [R=301,L]
RewriteRule ^videos/show/([^/]+)/([^/]+)/?$ /videos/show.php?id=$1&category=$2 [L,QSA,NC]

Try something like this:
RewriteEngine on
Options +FollowSymlinks
RewriteBase /mysite
RewriteRule ^videos/show/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)$ /videos/show.php?id=$1&category=$2
And Check mod-rewrite module of apache must be enable. If not than enable it and restart your server again.

Related

Godaddy question mark and variable name hide php get

I have been trying for the past few days to get a Godaddy hosted server to hide the question mark and the variable name in the url automatically (ie. mysite.com/?id=5 >>> mysite.com/5) using Rewrite Rules in the .htaccess file.
My current .htaccess file looks like this:
RewriteEngine On
Options -MultiViews
RewriteBase /
RewriteRule ^/(.*)$ /index.php?id=$1 [P]
Am I doing something wrong or is it the Godaddy servers? Thank you in advance!
Try adding the following into your .htaccess file.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^index/(\d+)*$ ./index.php?id=$1
You can learn more about clean urls here: http://www.desiquintans.com/cleanurls

Using RewriteRule shows apache folder navigation or 404, why?

I have wordpress installed and in the root i created a folder and put an .htaccess inside to redirect to another web page without changing the URL.
This was working fine until i move to another server (the older one was just horrible) and now it just not working.
This is code that i was using:
RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/conexionalam
RewriteRule ^(.*)$ http://nuevoserver.breinguash.com/$1 [R=301,L,P]
and is no longer working, show me this:
looking for internet i have tested some other codes:
1-
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^/conexionalam(/.*|)$ nuevoserver.breinguash.com$1 [L,NC]
2-
RewriteEngine ON
RewriteRule ^/(.+) http://nuevoserver.breinguash.com/$1 [R,L]
This two show me this:
3-
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://nuevoserver.breinguash.com/$1
This one redirect me to http://nuevoserver.breinguash.com/index.html
I realized that if i took off this '[R=301,L,P]' at the end of the first code, it works but changing the URL and i don't want tat.
Thanks in advanced!
EDIT:
By the moment im using this code:
RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/conexionalam
RewriteRule ^(.*)$ http://nuevoserver.breinguash.com/$1
Its redirects but change the URL = /
but for now does not affect google analytics.
if i change or add something to the code it does show me the errors from above. i really doesn't understand why it does that.
SOLUTION
Well it seem that i cant redirect between domains/subdomains without changing the URL just like that, i have to do it with proxy, so the solution was:
Enable proxy and proxy-http on apache.
Use the P flag for RewriteRule
So right now i'm using this code and it works perfectly:
RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/conexionalam
RewriteRule ^(.*)$ http://nuevoserver.breinguash.com/$1 [R=301,L,P]
Give this a shot in your .htaccess file...
RewriteEngine On
RewriteBase /
RewriteRule ^conexionalam(.*)$ http://nuevoserver.breinguash.com/$1 [L,R=301]
This should redirect you to http://nuevoserver.breinguash.com when you go to /conexionalam from your main domain.

htaccess stopped working after moving website to subdomain

So, I moved the website.com to subdomain.website.com. The .htaccess file is located in the website.com/subdomain/ folder, it should work but it's not working.
Error message: The requested URL /title-123 was not found on this server.
Basically what it does is translates the website.com/product.php?id=123&title=hello to website.com/hello-123
The error is produced when trying to access subdomain.website.com/title-123
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/product\.php\?id=([0-9]+)&title=([^\s&]+)\s [NC]
RewriteRule ^ %2-%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+?)-([0-9]+)$ product.php?id=$2&title=$1 [L]
</IfModule>
Anyone knows how to fix this? Thanks!
After a lot of research and debugging of apache conf files and receiving expert's assistance i managed to fix it removing completely the .htaccess file and adding the rewrite rules in the apache VirtualHost directly.

mamp pro htaccess rewriteRule not working

i have already search for a long time and i could not figure our why Rewrite Rule is not working. i want to translate this url
http://localhost/uniwood/template-allgemein.html?postname=kontakt&pageid=27
to
http://localhost/postname/kontakt.html
here the code in the htaccess file
RewriteEngine On
RewriteRule ^postname/([^/]*)\.html$ /uniwood/template-allgemein.html?postname=$1&pageid=27 [L]
I'am using locally on my machine the mamp pro webserver and checked that AllowOverride is on "all".
I do not get any mistakes! Also no error logs!
thanks!
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{THE_REQUEST} /template-allgemein\.html\?postname=([^\s&]+)&pageid=27 [NC]
RewriteRule ^ /postname/%1.html? [R=302,L,NE]
RewriteRule ^postname/[^.]+)\.html$ /template-allgemein.html?postname=$1&pageid=27 [L,NC,QSA]

friendly url htaccess using variable

Target is to create friendly URL, and I got stuck here.
My link below:
Turpināt lasīt..
My .htaccess
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^blog/([0-9]+)/?$ blog.php?id=$1
No problems in configuration, simple rewrite rules work. What's wrong here?
Thanks
Ok try this code:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+blog\.php\?id=([^\s&]+) [NC]
RewriteRule ^ /blog/%1? [R=301,L]
RewriteRule ^blog/([0-9]+)/?$ /blog.php?id=$1 [L,QSA]

Categories