I have some images url like: http://example.com/12345-large_default/image.jpg
And I want to get the 12345 and rewrite to: http://example.com/app/img.php?id=12345
I have tried this and a lot of changes:
RewriteRule ^([0-9]+)\-large_default.jpg$ /app/img.php?id=$1
But I can't get it working.
Add this rule to your .htaccess file and it will work.
RewriteRule ^12345-large_default/image\.jpg$ /app/img.php?id=12345&%{QUERY_STRING}
Related
I would like to redirect all my urls replacing %23 with a # in my htaccess file
Example: http://afdelingtest.nl/vierdaagsefeesten/programma/%23jaap-categorie should be http://afdelingtest.nl/vierdaagsefeesten/programma/#jaap-categorie
The last part 'jaap-categorie' differs.
I tried many example Htaccess lines but nothing seems to work. Like: RewriteRule ^(.#.) /$1 [R,NE]
Can somebody help me achieve this?
Best, Jaap
This expression might help you to write a RewriteRule and do so:
^(.*)(%23)(.*)$
The hex code for hashtag is \x23. You want to replace it with $1\x23$3.
This graph shows how that expression would work:
Your RewriteRule might look like something similar to:
RewriteRule ^(.*)(%23)(.*)$ $1\x23$3 [NE,R=301,L]
or
RewriteRule ^(.*)(%23)(.*)$ $1\x23$3 [NE,R=302,L]
302 is temporary and 301 is permanent, however you wish. You might want to do a 302, then change it to 301.
You might want to clear your browser cache every time you change your .htaccess file.
I'm assuming that you have one %23 in your URLs.
I currently have the following .htaccess rewrite rule setup on my site:
RewriteEngine On
RewriteRule ^([^/d]+)/?$ index.html?id=$1 [QSA]
The rule works in such a way that if I go to the following URL:
http://example.com/dashboard
It won't try and find the dashboard directory that doesn't exist but instead it will keep the URL as is and redirect the user to the root index page. From there I just use javascript to control what view the user will see depending on what path is appended.
The code works exactly as I want it to but i've now had to move my site into a sub-directory on our server. The URL structure is now this:
http://example.com/mysubdir/dashboard
I tried rewriting my rewrite rule to incorporate the directory but have not been successful so far as i'm no .htaccess expert. I tried something along the likes of:
RewriteEngine On
RewriteRule ^([^/d]+)/mysubdir/?$ index.html?id=$1 [QSA]
Could anyone tell me how I can amend my rewrite rule to work in my sub-directory?
You were close - this should do it:
RewriteEngine On
RewriteRule ^mysubdir/([^/d]+)/?$ /mysubdir/index.html?id=$1 [QSA]
Demo here: http://htaccess.mwl.be?share=6e574cc6-90a4-54ca-b113-ce72d6eb5203
i need some help rewriting URL using .htaccess my urls looks like:
http://www.example.com/testro2/product.php?id=426834&productStore=396
And i need have it work with text into it, example:
http://www.example.com/testro2/product/{anythinghere}/id=4268334&productStore=369
or you can make it look more clear like removing id= and &productStore= will be great, else i can use with them. example
http://www.example.com/testro2/product/{anythinghere}/4268334/396
The thing is that i need to have my keyword anythinghere in the URL.
Also, i would like to rewrite
http://www.example.com/testro2/search.php?q=shoes
TO
http://www.example.com/testro2/search/shoes
You can put this code in your /testro2/.htaccess
RewriteEngine On
RewriteBase /testro2/
RewriteRule ^product/.+/(\d+)/(\d+)$ product.php?id=$1&productStore=$2 [L]
RewriteRule ^search/(.+)$ search.php?q=$1 [L]
I have a site which has a url structure like so:
url/example1/sometext
So I dont have to go through and change a crazy amount of code, can I use htaccess to do the following?
url/newword/sometext redirects to: url/example1/sometext with url/newword/sometext still shown the address bar.
I have tried some rewrites like:
RewriteRule ^(.*)example1(.*)$ url/$1newword$2 [R=301,L]
Any ideas?
As long as the "url" part is still the same, then you can just get rid of the R=301 flag:
RewriteRule ^(.*)example1(.*)$ /$1newword$2 [L]
I want to write a clean URL for my application. I searched and have written following, but it does not work and gives "Server not found error".
I have URL like this
http://localhost/projectFolder/user_folders/userName/testSite2/
and I want it to be -
http://testSite2.mySystemDomain.com/
I have tried as follows, but it fails.
RewriteEngine on
RewriteRule ^/user_folders/userName/testSite2/(.*) http://testSite2.mySystemDomain.com/$1
EDIT
There will be number of sites like testSite2. I need to write the URL for each such site.
Put this in .htaccess in folder projectFolder
RewriteEngine on
RewriteRule ^user_folders/(.*)/(.*) http://$1.mySystemDomain.com/$2 [R=301,L]