htaccess using QSA returning 404 - apache

I'm trying to direct a url for a blog post to a PHP page that takes a GET var using htaccess.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/post/(\w+)$ blog/post.php?title=$1 [QSA,L]
However, this just gives me a 404. I have confirmed that /blog/post.php?title=my-postis a valid url.

Since your title contains hyphens your rule should allow it:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/post/([\w-]+)$ blog/post.php?title=$1 [QSA,L,NC]

Related

How to stop url from from adding amp%3B

Im having a problem with my URLs. for an example when i click on the below link
mysite.com/category?language=nl&currency=USD%26utm_campaign%3Dgoogle_shopping%26utm_source%3Dgoogle_shopping%26utm_medium%3Dgoogle
it redirects to
mysite.com/category?language=nl&currency=USD%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Butm_campaign%3Dgoogle_shopping%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Butm_source%3Dgoogle_shopping%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Butm_medium%3Dgoogle
and give the below error
The page isn’t redirecting properly
the url adds multiple amp%3B and breaks it
my htaccess has the below
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
can someone tell me why is multiple amp%3B to the url and how can i stop it?
is it possible to remove all the url content after currency=USD so the url works?

URL Rewriting Using .htaccess for PHP

I want to convert this URL example.com/post.php?id=12345&title=xyz to example.com/12345/xyz.
I am able to do example.com/12345 but I can't get /xyz.
RewriteEngine On
RewriteRule ^post/([a-zA-Z0-9-/]+)$ post.php?id=$1
RewriteRule ^post/([a-zA-Z-0-9-]+)/ post.php?id=$1
With your shown samples, please try following htaccess Rules. Please make sure to clear your browser cache before testing your URLs.
This solution assumes that you are hitting example.com/post.php?id=12345&title=xyz sample url in browser and want to change it to example.com/12345/xyz
##Enabling engine here.
RewriteEngine ON
##Extrenal redirect 301 to mentioned url by OP in question.
RewriteCond %{THE_REQUEST} \s/post\.php\?id=([^&]*)&title=(\S+)\s [NC]
RewriteRule ^ %1/%2? [R=301,L]
##Internal rewrite to post.php with query strings.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/?$ post.php?id=$1&title=$2 [QSA,L]

htaccess remove specific get parameter from url

I'm using Google OAuth to connect to the dashboard, the problem is that when the GET &scope parameter of the callback contains a URL like "https://www.googleapis.com/auth/userinfo.profile", the host return an Error 403.
So after many researches the only solution I found is to remove scope from the url.
I want to change the callback url from this:
https://msite.com/?code=xxx&scope=email%20profile%20https://www.googleapis.com/auth/userinfo.profile%20https://www.googleapis.com/auth/userinfo.email
To this
https://msite.com/?code=xxx&scope=true
Here is my basic htaccess
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php?a=$1 [QSA,L]
You can use this :
RewriteEngine on
RewriteCond %{THE_REQUEST} /\?code=([^&]+)&scope=email.+ [NC]
RewriteRule ^$ /?code=%1&scope=true [L,R=301]
This will redirect your URLs from
/?code=Sometext&scope=emailSometext
To
/?code=Sometext&scope=true

404 error in url rewriting to get user-friendly urls

I have a static html website on a shared hosting.
I would like to turn these html files to user-friendly urls.
IE: website.com/web-design.html becomes website.com/web-design/
I am using these rules so that the corresponding html file is served when I request website.com/web-design/:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^\.]+)$ $1.html
It works if I type in the browser website.com/web-design (without trailing slash), but instead with website.com/web-design/ I get a 404 error:
The requested URL /web-design.html/ was not found on this server.
I want both urls (with and without trailing slash) to work...
It seems that a slash is added at the end of the html file, giving a 404.
I can't figure out how to fix it...
Thanks for your help.
You should try your rule like this
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /$1.html [L]

.htaccess RewriteRule not working, bad flag delimiters

My site previously uses URL's like this: /folder/page
Previously, you could prepend 'panel' in the URL to edit the current page: /panel/folder/page
We upgraded our CMS, and the new URL to edit the page is in this format: /panel/#/pages/show/folder/page
I am trying to add a rewrite rule so that we can still use the old way, but can't get it to work:
RewriteCond %{REQUEST_URI} !^/panel/#/
RewriteRule /panel(.*) /panel/#/pages/show/$1
Is there a way to do this? A 301 redirect should work too, I think.
Edit: here is my existing .htaccess:
RewriteEngine on
RewriteBase /
# make panel links work
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^panel/(.*) panel/index.php [L]
# make site links work
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php [L]
Since "panel" is already used, I ended up using this redirect rule:
RedirectMatch 301 /admin(.*) /panel/#/pages/show/$1