.htaccess change the URL page with three conditions - .htaccess

I want to change the url of my page like
http://localhost/Dynobase/my_computer.php?name=Deny-computer&type=computer&select=1
to
http://localhost/Dynobase/Deny-computer/computer/data/1
and to my htaccess file code like this
RewriteRule ^([a-zA-Z_-]+)/([a-zA-Z_-]+)/data/([[0-9]]+)$ /my_computer.php?name=$1&type=$2&select=$3 [L,NC]
but that I could actually error 404
maybe there is something wrong in my code.
please help me.
Thank you

Try this in /Dynobase/.htaccess:
RewriteEngine On
RewriteBase /Dynobase/
RewriteRule ^([\w-]+)/([\w-]+)/data/([0-9]+)/?$ my_computer.php?name=$1&type=$2&select=$3 [L,NC,QSA]

Related

What is wrong htaccess

I have the following htaccess rules but I dont know how to make it work:
RewriteEngine on
RewriteRule ^game/([^/]*)$ index.php?cash=$1
The following is the screen shot of my folders structure:
Can someone tell me how to get it to work? I have also tried:
RewriteRule ^index.php([^/]*)$ index.php?cash=$1
The URL that I want to display is: http://localhost/biteep/game/100 while the URL that I want the browser to go to is http://localhost/biteep/game?cash=100
Try to put a rewrite base into your .htaccess:
RewriteBase /biteep/
And this route should be enough:
RewriteRule ^game\/(\d+)$ index.php?cash=$1
So it works when I do this
RewriteEngine on
RewriteRule ^([0-9]+)$ index.php?cash=$1

Mod_Rewrite with .htaccess is not working

I just learnt about url-rewrite for my website with .htacess. My actual url is:
localhost/index.php?view=some-page
So i write this RewriteRule like this:
RewriteRule ^/([^/]*)/?$ /index.php?view=$1 [NC,L]
When i typed localhost/homepage on my browser, It does not work, it displays error 404 object not found. What have i done wrong please show me.
Many thanks
This should work in your DocumentRoot/.htaccess:
RewriteEngine On
RewriteBase /
RewriteRule ^([^/]+)/?$ index.php?view=$1 [QSA,L]
Leading slash is not matched in htaccess.
are you using apache?
This link from step 6 helped me
https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-on-ubuntu-14-04
When i was playing around with rewrites i had to enable it and tell apache where the pages were stored

change url and access to file by htacess

My real url is:
/a/bc/de/test/1.jpg
I want access to my file by this url without redirect:
/abcde/test/1.jpg
How can i do that?
This is pretty strange rewrite rule but you can try this rule in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteRule ^([a-z])([a-z]{2})([a-z]{2})/(test/.+)$ /$1/$2/$3/$4 [L,NC]
Tanx for help, this is correct:
RewriteRule ^([0-9a-f]{1})([0-9a-f]{2})([0-9a-f]{2})/([0-9a-z-]{1,})/(.+)$ /$1/$2/$3/$4/$5 [L,NC]

.htaccess rewrite with GET param

Im trying to transfrom link like this:
http://localhost/photohosting/user/view.php?img=60
Into something like that in users browser:
http://localhost/photohosting/60
Here my code for .htacces
RewriteEngine on
RewriteRule ^view.php(.*)$ /photohosting/user/view.php?img=$1 [L,QSA]
I'm not familiar with .htaccess so I can't found the mistake. Why this code doesn't work?
UPDATE: I've updated my .htaccess to:
RewriteRule ^([a-zA-Z0-9_-]+)$ user/view.php?img=$1 and now link like http://localhost/photohosting/60 works, but it misses param.
Try with the following rule:
RewriteRule photohosting/([0-9]+)$ /photohosting/user/view.php?img=$1 [L,QSA]

.htaccess: how to only rewrite .php URL?

My rewriterule with a condition is working fine as below:
http://www.sitename.com/index.php?n=text redirects to
http://www.sitename.com/pages/text
and the page renders properly, however, there is a problem that with the redirected URL the arguments are also added to the URL. So actually in address bar it looks like-
http://www.sitename.com/pages/text?n=text
Could anyone help me on this? The htaccess code is given below.
RewriteCond %{QUERY_STRING} ^n=(.*)$
RewriteRule index.php http://www.sitename.com/pages/%1 [r=301,nc]
You probably want to catch "index.php.*". Otherwise mod_rewrite only replaces the "index.php" part of the URL "index.php?n=text" with the new URL.
Guss,
From what you suggested, i reconstructed it as follows:
RewriteCond %{QUERY_STRING} ^n=(.*)$
RewriteRule index.php.* http://www.sitename.com/pages/%1 [r=301,nc]
This doesnt seem to be working either. Can you please elaborate on what you have said?
thank you
aditya
donĀ“t use the url in the rewrite rule, apache then sends a http 200 code and then the 301...
try sth. like this:
RewriteRule (index\.php)(?n=)(.*) /pages/$3 [r=301]

Resources