I am getting error while making htaccess seo friendly url - .htaccess

I'm doing 3 $_GET operations: page=, blog_id= and blog_Title=
There is index.php in the blog folder... I'm getting a page not found error, can you help?
I include pages in index.php with $_GET["page"]
RewriteRule ^blog/([0-9a-zA-Z-_]/([0-9])+)$ blog/index.php?page=$1&sef=$2&blog_ID=$3 [L,QSA]

Try this placed in folder "blog"
RewriteRule ^([^.]+)$ index.php?page=$1&sef=$2&blog_ID=$3 [QSA,L]

Related

htaccess Rewrite Error, Can not fetch $_GET value PHP :(

I am sorry to open a replicated question once again but I had no other choice. I am trying to write a clean URL using .htaccess. Here is my code:
RewriteRule ^home index.php [NC,L]
RewriteRule ^about-us about-us.php [NC,L]
RewriteRule ^careers careers.php [NC,L]
RewriteRule ^contact-us contact-us.php [NC,L]
these works very finely. but when I move on to URL's having some GET params like
example.com/providers.php?provider=huawei
and the htaccess rule goes as:
RewriteRule ^providers/([a-zA-Z_-]+) providers.php?provider=$1 [NC,L]
When I navigate to the URL example.com/providers/huawei it throws an error
Notice: Undefined index: provider in directory\providers.php on line x
Appearantly, there is no error in the rule, I have gone through several video and StackOverflow solutions. Some suggested the use of QSA but no luck. I changed my production servers too still negative. Any help in this regard.
TIA

Redirect already SEO friendly URL to another SEO friendly URL externally using .htaccess

Part of my .htaccess code is as follows:
RewriteRule ^([A-Z]+)*$ nextlevels_state.php?state=$1 [L]
RewriteRule ^([A-Z]+)*/([0-9]+)$ nextlevels_state.php?state=$1&page=$2 [NC]
This basically redirects URL, example.com/XX to example.com/nextlevels_state.php?state=XX and example.com/XX/1 to example.com/nextlevels_state.php?state=XX&page=1 (internally).
Now, I would like to change the URL structure of the URL from example.com/XX to example.com/nextlevels/XX and example.com/XX/1 to example.com/nextlevels/XX/1
and I tried changing .htaccess to as follows:
RewriteRule ^nextlevels/([A-Z]+)*$ nextlevels_state.php?state=$1 [L]
RewriteRule ^nextlevels/([A-Z]+)*/([0-9]+)$ nextlevels_state.php?state=$1&page=$2 [NC]
However, as the site urls are already indexed in search engines, I would like to know a way to redirect all the traffic from example.com/XX to example.com/nextlevels/XX (externally) using .htaccess .
Please guide me in this regard. Thank you community :)
Could you please try following, written and tested with shown samples only(improving your already done attempts here). Please make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
##Rule for redirect to url example.com/nextlevels/XX.
RewriteRule ^([A-Z]+)$ nextlevels/$1 [R=301]
RewriteRule ^nextlevels/([A-Z]+)/?$ nextlevels_state.php?state=$1 [NC,L]
##Rule for redirect to url example.com/nextlevels/XX/1.
RewriteRule ^([A-Z]+)*/([0-9]+)$ nextlevels/$1/$2 [R=301]
RewriteRule ^nextlevels/([A-Z]+)*/([0-9]+)$ nextlevels_state.php?state=$1&page=$2 [NC,L]

.htaccess rewriterule empty parameters note found error

.htaccess RewriteRule code:
RewriteRule ^urunler/([0-9a-zA-Z-_]+)/([0-9]+)/?$ urunler.php?kategori_id=$1&page=$2 [L,QSA]
I am going to this url "example.com/urunler/hi-tech-cadirlar/1".There is an error in this URL. But "example.com/urunler/hi-tech-cadirlar" this url go to 404 not found page.
I can not make pagination. I dont want the error Empty paramters.
You can use two different rules, one for pagination and another without pagination:
RewriteRule ^urunler/([\w-]+)/?$ urunler.php?kategori_id=$1&page=$2 [L,QSA,NC]
RewriteRule ^urunler/([\w-]+)/(\d+)/?$ urunler.php?kategori_id=$1&page=$2 [L,QSA,NC]

Get the language from URL with .htaccess

I have several languages on my site.
At the root I have a index.php. It's my homepage.
I want this type of url : domain.com/fr/ or domain.com/en/
Witch must be the same as domain.com/index.php?lang=fr or domain.com/index.php?lang=en.
So I use this .htaccess rule:
# Redirect to a page (xxxxx.com/index.php?lang=fr)
RewriteRule ^(fr|en|es|cn|ar)/index$ index.php?lang=$1 [L]
But it don't work.
Could you please help me with that ?
Thanks.
You can use:
RewriteEngine On
RewriteRule ^(fr|en|es|cn|ar)/$ index.php?lang=$1 [L]

modrewrite website with slash in .htaccess

How can I translate an URL like:
http://localhost/mySite/?link=OFFERS&sublink=ARTICLE&subsublink=DETAIL
to:
http://localhost/mySite/OFFERS/ARTICLE/DETAIL
if one parameter is empty it should still work like this:
localhost/mySite/?link=OFFERS&sublink=ARTICLE
localhost/mySite/OFFERS/ARTICLE
Extra problem: There is an enter page under index.php and the rewrite should work with index2.php. Best would be if it would work under localhost and on live system without changes.
Currently I'm using: RewriteRule ^([^/.]+)$ index2.php?link=$1 [L]
But that only works for one parameter and I couldn't improve this code for ages ^^
RewriteRule ^([^/.]+)(/([^/.]+))?(/([^/.]+))?$ index2.php?link=$1&sublink=$3&subsublink=$5 [L,QSA]
Note that localhost/mySite/OFFERS/ARTICLE links to localhost/mySite/?link=OFFERS&sublink=ARTICLE&sussublink= and not localhost/mySite/?link=OFFERS&sublink=ARTICLE.
Should not be a big issue, but make sure the PHP code doesn't us isset($_GET['subsublink']).
Try adding the following to your htaccess file in the mysitedirectory of your site.
RewriteEngine on
RewriteBase /mysite/
# rewrite http://localhost/mySite/OFFERS/ARTICLE/DETAIL to
# http://localhost/mySite/?link=OFFERS&sublink=ARTICLE&subsublink=DETAIL
#assumes that index2.php is in the root directory of site
RewriteRule ^([-a-zA-Z0-9])+/([-a-zA-Z0-9])+/([-a-zA-Z0-9])+ index2.php?link=$1&sublink=$2&subsublink=$3 [NC,L]
#redirect index to index2
#if you do not want to redirect, just server rewrite, remove the R=301 below
RewriteRule ^index\.php$ index2.php [NC,L,R=301]

Resources