Url with 2 parameters / rewriting in .htaccess - .htaccess

I host my website on a godaddy webserver and i try to use .htaccess file to rewrite some urls but it doesn't work. Help would be very appreciated.
Basically I would like to replace an url like:
https://www.example.com/photographers/photographer.php?id=1&name=john-doe
in:
https://www.example.com/photographer/1/john-doe
Parameter 1 is: id / Parameter 2 is: name
Obviously I would like also my server to redirect internally in the opposite way.
I tried a lot of combinations but with the rewriterule but none is working. For example I tried:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^photographer/(\d+)/([A-Za-z-]+)/?$ photographers/photographer.php?id=$1&name=$2 [NC,L]
Thank you for your help!

Related

URL Rewrite Rule shows blank page with text

i'm learning how to rewrite urls and im trying to do that in my ubuntu server. I managed myselft to activate the Allowoverride All and i have htacess working.
I want to change this url for example:
http://serverismai/myapi/public/rest/navigate.php
And i try to do it like this :
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^home(.*)$ myapi/public/rest/curso/navigate.php/$1 [L]
</IfModule>
I've tried various solutions but this was the closest i got. The url dosent change automatically but if i insert http://serverismai/myapi/public/rest/home i see a blank page with some of my website html written ( not even the html of the page i'm trying to rewite url).
I'm pretty new to this so i want to know if there is something wrong in the Rewrite Rule or if my error is somewhere else...
Thank you!
You can use this code in your /myapi/public/rest/.htaccess file:
RewriteEngine On
RewriteBase /myapi/public/rest/
RewriteRule ^home/?$ curso/navigate.php [L,NC]

.htaccess variables REWRITING but not REDIRECTING

I've been looking for my answer for 2 days but since I haven't found it, I finally decided to put my question to you.
I'm using a Brinkster shared host and can access the .htaccess but no Apache configuration. Every folder on the server represents the content of one site (domain). In the root I have a .htaccess where every domain is controled with
RewriteCond %{HTTP:Host} ^(?:www\.)?domainname\.be$
RewriteRule (.*) /folder/$1 [NC,L,NS]
In the folder I have another .htacces file.
I want to rewrite and redirect for prettier URLs
http://www.domainname.com/pag.asp?name=var_name&id=var_id
should look like
http://www.domainname.com/name/
The rewrite bit works with the .htaccess code bellow.
<IfModule mod_rewrite.c>
RewriteEngine On
Options +FollowSymLinks -MultiViews
Options FollowSymLinks
AllowOverride All
RewriteBase /folder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^name=([a-zA-Z-]+)&id=([0-9]+)$ [NC]
RewriteRule ^/?page\.asp$ /%1? [R=301,L]
</IfModule>
But for some reason www.domainname.com/name/ always gives a 404.
What am I doing wrong?
Any help wouldd be highly appreciated.
Thank you

HTACCESS short url and modify my url

How can I use .htaccess to make this URL
http://domain.com/index.php/sub1/sub2/333
look like
http://domain.com/333
?
Thank you very much!
I tried everything and I tried to find everywhere the answer, but nothing works.
This is my htacces, maybe can help you ( I hosted in hostgator,in hostgator is importan write your user, if is local remove ) this configuratio apply to multiple sites
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /<myuser>/%{HTTP_HOST}
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /<myuser>/%{HTTP_HOST}/index.php/$1 [L]
</IfModule>
You can replace %{HTTP_HOST} by your folder.
After if you want modify the controller name, you need modify in application/config/routes.php
Following rule should work for you:
RewriteEngine On
RewriteRule ^([0-9]+)/?$ /index.php/sub1/sub2/$1 [L]

htaccess config : using part of the URL as parameter

I'm using a URL shortener and i'd like to have the following :
from http://domain.com/ld541as2 redirecting to http://www.newsite.com/login-ld541as2.html
There are a lot of possible URL but i'm guessing it's possible to do it with 1 rule ?
Any chance any of you guys know how to do so ?
Thanks for your help
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /login-$1.html [L,R]
PS: If you don't want full (external) redirection then remove R flag from above rule.

Rewrite rule not working as expected?

I have a URL with a parameter which I wish to make into sef URL:
want:
http://map.tautktiv.com/street.php?address=abc
to become:
http://map.tautktiv.com/street/address/abc
or
http://map.tautktiv.com/address/abc
have tried several online tools to generate a .htaccess rule, but none of them have any effect on the URL, .htaccess file is active (tried to put some gibberish in it and got error 500)
these are the rules I tried:
1.
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^address-([^-]*)$ /street.php?address=$1 [L]
RewriteRule street/address/(.*) street.php?address=$1
2.
Options +FollowSymLinks
RewriteEngine on
RewriteRule /address/(.*)\.php street.php?address=$1
3.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# add whatever other special conditions you need here
RewriteRule ^/([0-9]+)-(.*)$ /street.php?address=$1 [L]
RewriteRule /(.*)/(.*)/$ street.php?address=$1
the site is a sub-domain which files reside in a sub directory in a shared hosting GoDaddy server, have also tried to apply these rules to the .htaccess in the directory above it, same result.
tried also this per below suggestions
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^street/address/(.*)$ street.php?address=$1 [r=301,L]
RewriteRule ^address/(.*)$ street.php?address=$1 [r=301,L]
RewriteRule ^street/address/(.*)$ street.php?address=$1 [r=301,L]
same result, nothing happens.
tried to go directly to page from main domain but same result:
http://tautktiv.com/map/streets/street.php?address=abc
First rule will redirect your ugly URL to the pretty URL.
Second rule will internally redirect it back so the user will not see the ugly URL.
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
# Internally forward /street/address/abc to /street.php?address=abc
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^street/address/(.*)/?$ /street.php?address=$1 [NC,L]
# Internally forward /address/abc to /street.php?address=abc
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^address/(.*)/?$ /street.php?address=$1 [NC,L]
If you confirm the rule to be working as expected then you can change it from 302 to 301 as you do not want to use 301 until you know the rule is working as expected.
The .htaccess should go inside the folder where street.php is located.
HTTP is US ASCII so your language would fail, it will redirect it to something like this:
/street/address/%25D7%2590%2520%25D7%2598%25D7%2591%25D7%25A8%25D7%2599%2520%25D7%2599%25D7%25A8%25D7%2595%25D7%25A9%25D7%259C%25D7%2599%25D7%259D%2520%25D7%2599%25D7%25A9%25D7%25A8%25D7%2590%25D7%259C
Your best bet here would be to change the links to use /street/address/word instead of the php file directly.
This way you would not need the first rule and you can use only the internal redirect which would work just fine with this update.
Try this one:
RewriteEngine on
RewriteRule ^street/address/(.*)$ street.php?address=$1 [r=301,L]
RewriteRule ^address/(.*)$ street.php?address=$1 [r=301,L]
In your examples you'd missed ^ and $ in the second row of RewriteRule.
And use [r=301,L] instead of [L] to tell the browser, that thzis is premanent redirecting.

Resources