I have a url that looks like this
http://example.com/index.php?con=something&met=meh
What i'm trying to do is get rid of con= and met= so the url would look like
http://example.com/index.php/something/meh
That's what i've done so far
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ action=$1 [L,QSA]
RewriteRule ^(.*)$ page=$1 [L,QSA]
but nothing changes, the url it still look the same http://example.com/index.php?con=something&met=meh
What am i doing wrong?
I did like this:
RewriteEngine on
RewriteRule ^index.php/([^/]+)/?([^/]*) /index.php?con=$1&meh=$2 [NC]
Notice that if you don't pass any meh, it still works.
Related
My URL looks like this:
example.com/index.php?f=directory&s=page
I want it to be like this instead:
example.com/directory/page
my rewrite rules look like this right now:
RewriteRule ^([A-Za-z0-9]+).html$ https://www.example.net/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?(.*?)/?$ index.php?s=$1 [L]
it appears to work but not quite because if I call the queries in PHP I get something like this:
print $_GET['f'] */ it prints nothing
print $_GET['s'] */ it prints directory/page
which is not what I intend. How can I fix it?
Thank you.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?(.*?)/?$ index.php?s=$1 [L]
Do it like this instead:
RewriteRule ^([^/]+)/([^/]+)$ index.php?f=$1&s=$2 [L]
Request /directory/page and it internally rewrites the request to index.php?f=directory&s=page.
By making the regex more specific, the filesystem checks can probably be avoided.
To redirect from index.php?f=directory&s=page to /directory/page (if these URLs have already been indexed and/or linked to by third parties), then add the following redirect before the above directive:
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^f=([^&]+)&s=([^&]+)$
RewriteRule ^index\.php$ /%1/%2 [R=301,L]
But you must already be linking to the canonical /directory/page URL in your application.
Test with 302s to avoid potential caching issues. Clear your browser cache before testing.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?(.*?)/?$ index.php?s=$1 [L]
You are only assigning a single URL parameter s, so yes, $_GET['f'] will indeed be empty.
My code produce URL like this:
http://domain.com/netRacuni/tcpdf/examples/pdf.php?key=bi5u3w2zys1v9sqijomsqyya5ge2v5
How I can make it like this:
http://agroagro.com/bi5u3w2zys1v9sqijomsqyya5ge2v5
so only domain.com+key to be there?
You can a try a rule like this in your root .htaccess.
RewriteEngine On
RewriteCond %{QUERY_STRING} ^key=(.+)$
RewriteRule ^netRacuni/tcpdf/examples/pdf.php$ /%1? [L]
Edit: Sounds like you want it the other way around. Your question isn't too clear.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /netRacuni/tcpdf/examples/pdf.php?key=$1 [L]
My original url was this:
wwww.domain.com/car-details.php?merk=BMW&model=X5&titel=sale&car_id=3
I have Rewrite it into this:
wwww.domain.com/BMW/X5/sale/3
By putting this in my .htaccess:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)/(.*)/([0-9]+)?$ /car-details.php?merk=$1&model=$2&titel=$3&car_id=$4 [L,QSA]
When i put in Url wwww.domain.com/car-details.php?merk=BMW&model=X5&titel=sale&car_id=3 it still works. I want that url to be redirected to wwww.domain.com/BMW/X5/sale/3
I have tried to put the [R] flag in my htaccess RewriteRule but then I'm getting the opposite results.
How can I fix this?
This is a good decision to do what you want.
But you will face a loop problem.
You can avoid it by using this code
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/car-details\.php\?merk=([^&]+)&model=([^&]+)&titel=([^&]+)&car_id=([0-9]+) [NC]
RewriteRule . /%1/%2/%3/%4? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([0-9]+)?$ /car-details.php?merk=$1&model=$2&titel=$3&car_id=$4 [L]
I have a URL:
domain.com/abc/hotel_detail.php?id=2
And I want to do a URL re-write to make it look like this :
domain.com/abc/hotel_detail/2
My current .htaccess looks like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{QUERY_STRING} ^id=20$
RewriteRule ^abc/hotel_detail/([0-9]+)$ ^abc/hotel_detail.php?id=$1 [L]
The first part contains code for removing the extension(.php) from pages.
When I try to open this link domain.com/abc/hotel_detail/2 , it gives me object not found error.
Can Someone please tell me whats wrong with the code?
Remove this line:
RewriteCond %{QUERY_STRING} ^id=20$
Changing your file to:
RewriteEngine On
RewriteRule ^abc/hotel_detail/([0-9]+)$ ^abc/hotel_detail.php?id=$1 [R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,R]
should work. I removed RewriteCond %{QUERY_STRING} ^id=20
Your first rewritecond and rule was overwriting the second one, switching them around should fix it.
I think this should work
RewriteRule ^abc/hotel_detail/([0-9]*)$ abc/hotel_detail.php?id=$1 [L]
([0-9]*) miltiply sign.
and the ^ for the real link
I'm newbie in htaccess..
I have some conditions like this..
if user access
first/second/third
it's equal to
first.api.php?rquest=second&attr=third
but if the value of rquest is 'index', it will be erased from URL, like
first/third
equal to
first.api.php?rquest=index&attr=third
not
first/index/third
I had all night looking for solution, but no result.
I know system being confused if the request is index but attr has a value, it will treat the attr like rquest. see above, first/third, system will treat the 'third' segment as rquest.
Is it possible to rewrite url like that?
this is my work all night, I know this is still crap..
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s
RewriteCond %{QUERY_STRING} !rquest=index
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ $1.api.php?rquest=$2&attr=$3 [NC]
RewriteRule ^([a-zA-Z0-9_-]+)/(.*)$ $1.api.php?rquest=$2 [QSA]
RewriteCond %{REQUEST_FILENAME} -s
RewriteCond %{QUERY_STRING} rquest=index
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ $1.api.php?rquest=index&attr=$2 [NC]
RewriteRule ^([a-zA-Z0-9_-]+)$ $1.api.php?rquest=index [QSA,L]
</IfModule>
Try something like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ /$1.api.php?rquest=$2&attr=$3 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ /$1.api.php?rquest=index&attr=$2 [L,QSA]
Not clear what you were trying to achieve with your old rewrite rules, but the above should do what you've described.