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
Related
I have this .htaccess in my root folder:
root:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?page=$1&%{QUERY_STRING} [NC,L]
So that incoming GET requests come through http://www.example.com/somethingsomething instead of ?page=somethingsomething. That's all fine.
However, in the root folder I have another folder named /i. Id like this one to handle another type of request, which looks like this: http://www.example.com/i/somethingsomething with the ending actually meaning http://www.example.com/i/index.php?img=somethingsomething. Problem is that the .htaccess in the root folder is still in use. What I need is the following:
/i:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?img=$1&%{QUERY_STRING} [NC,L]
, but somehow exclude the .htaccess in the root folder.
Is this possible?
EDIT:
Tried what I found on this site, for instance using RewriteCond %{REQUEST_URI} !^/(i) and similar in the root .htaccess.
Yes, you can do it like this, using a single rule in the root .htaccess. The root .htaccess is always going to get processed, so you might as well do it there with one rule. Otherwise it would be more complicated and the root would need modifying with an exception for /i anyway.
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/(?:i/)?index\.php$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(i/)?(.*)$ /$1index.php?img=$2 [QSA,NC,L]
Using the [QSA] flag which is a better way to pass on any existing query string. RewriteBase is not needed. You perhaps don't need the directory check and it would be better for performance without it. The index.php check is there to improve performance by avoiding another file-system check after a successful rewrite.
Update
Sorry, I hadn't noticed that the parameter you are passing to index.php has a different name in the second case. These rules in root should work for you:
RewriteEngine on
RewriteCond %{REQUEST_URI} !=/index.php
RewriteCond %{REQUEST_URI} !^/i/ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?page=$1 [QSA,NC,L]
RewriteCond %{REQUEST_URI} !^/(?:i/)?index\.php$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^i/(.*)$ /i/index.php?img=$1 [QSA,NC,L]
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]
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]
Currently my website does this when you go to whoever's profile:
index.php?a=profile&u=berdyev
I would like to make it look like:
website.com/berdyev
Any suggestions?
Thank you.
Place this in your root .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /index.php?a=profile&u=$1 [L,QSA]
I am working on a CMS that requires an id and a title to be sent to the page content.php so that the data can be fetched from the database. I have tried to use:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([0-9]+)/(.*) content.php?id=$1&title=$2
But when I navigate to /id, it doesn't work, nor does it work if i do /id/title. What have I messed up here? Anything to remember for future use in .htaccess?
Thanks in advance!
You may try this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /([^/]+)/([^/]+)
RewriteRule .* http://example.com/content.php?key1=%1&key2=%2 [L]
It will map silently this:
http://example.com/id/title
To this:
http://example.com/content.php?key1=id&key2=title
Where /id in the incoming URL is the value of id key and the same for /title