How to short url address with .htaccess - .htaccess

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]

Related

.htaccess: Rewrite URI GET-Parameters?

I want my URL to look like this:
https://example-test.example.com/example-application_1.1/index.php?page=pagename&action=actionname
But the user should only type:
https://example-test.example.com/example-application_1.1/pagename/actionname/
Is it possible to make this run with a RewriteRule in .htaccess? I couldn't figure it out.
My .htaccess-file looks like this at the moment:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^example-test\.example\.com
RewriteRule ^example-application_1\.1/([^/]+)/([^/]+)/?$ /example-application_1\.1/index.php?page=$1&action=$2 [QSA,L]
I did it:
RewriteEngine On
RewriteRule "^([^/]+)/([^/]+)/([^/]+)" index.php?page=$1&action=$2&$3 [L]
RewriteRule "^([^/]+)/([^/]+)/" index.php?page=$1&action=$2 [L]
So if the user types in this:
https://example-prefix.example.com/pagename/actionname/id=123&category=456
The URL will be turned into this:
https://example-prefix.example.com/index.php?page=pagename&action=actionname&id=123&category=456
If you still want to have access on your files simply do this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule "^([^/]+)/([^/]+)/([^/]+)" index.php?page=$1&action=$2&$3 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule "^([^/]+)/([^/]+)/" index.php?page=$1&action=$2 [L]
RewriteEngine on
RewriteRule ^example-application_1.1/([^/]*)/([^/]*)/$ /example-application_1.1/?page=$1&action=$2 [L]
This should work.
In index.php, you can get variable: $_GET['page'] & $_GET['action'].
I think you can use:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule "^([^/]+)/([^/]+)" index.php?page=$1&action=$2 [L]

rewrite url to root directory with url cutting

I have such urls:
http://site.ru/ontent/wefwefw/article.php?article=369-tayskaya-kuhnya-recept-s-foto
http://site.ru/ontent/wefwefw/article.php?article=32237-ogurci-recepti-na-zimu
http://site.ru/ontent/wefwefw/article.php?article=90-ogurci-na-zimu-recepti-po-koreyski
I want to rewrite tham like:
http://site.ru/tayskaya-kuhnya-recept-s-foto.html
http://site.ru/ogurci-recepti-na-zimu.html
I tried smth like:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ ontent/wefwefw/$1 [L]
But how cut unnecessary parts of string?
Unless article.php is able to derive the right article from the title alone, what you want to do is not possible. mod_rewrite is good at rewriting things, but it can't summon an article-id from thin air if it isn't in the original request. You would have something like:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)\.html$ ontent/wefwefw/article.php?article=$1 [L]
When you would request http://site.ru/tayskaya-kuhnya-recept-s-foto.html, it will load http://site.ru/ontent/wefwefw/article.php?article=tayskaya-kuhnya-recept-s-foto. Then you have to get the id 369 in some other way based on the title if needed.
The best in this case is:
http://site.ru/369-tayskaya-kuhnya-recept-s-foto.html
redirect to
http://site.ru/ontent/wefwefw/article.php?article=369
with:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(\d+)-[^/]*\.html$ ontent/wefwefw/article.php?article=$1 [L]

if url not exist htaccess rewrite

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.

.htaccess rewrite /profile.php?username=Something

I had this code before
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /lr/profile.php?username=$1
But that makes the profiles go to coolsite.com/Something I want the profile link go to /profile/Something instead of profile.php?username=Something
How can i do that?
Unless there is more to your question then I'm seeing, simply changing your RewriteRule to something like the following should do the trick.
RewriteRule ^profile/(.*)$ /lr/profile.php?username=$1

removing two GET parameters from url using .htaccess

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.

Resources