Ugly url showing instead of pretty url - .htaccess

I'm facing an error that is driving me crazy.
I have this directive in my .htaccess:
RewriteRule ^([a-zA-Z0-9_+.\-]*)-barato$ buscar?controller=search&s=$1 [L,QSA,NC]
This directive is for the prestashop search engine. It is not keeping the nice url and is making a 301 redirect to the ugly url instead...
I have tried and searched all. I hope you know how to give me indications of where the fault may be.
UPDATE
Sorry for taking a long time to answer, I've had a brutal work season. I have tried what wp78de said (again, because I think I already tried this too) and it still does not work...
This htaccess has been working correctly in prestashop 1.6 for several years. However in none of the versions of prestashop 1.7 (1.7.2, 1.7.3, 1.7.4.1/2/3) in which I have tried it works.
It is a huge headache and surely it is silly, but I do not give with it...

If I understand this correctly, you want to rewrite without redirecting. This requires enabling mod_proxy and mod_rewrite in Apache's httpd.conf.
Then, the rewrite should look like this:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_+.\-]*)-barato$ buscar?controller=search&s=$1 [L,QSA,NC]
I've removed the E|ENV flag. It has no purpose here, does it?
Reference:
What exactly does the Multiviews options in .htaccess?
htaccess rewrite without redirect
Apache: RewriteRule Flags

Related

Rewrite example.com/index.php/... to example.com/... using mod_rewrite and .htaccess

I am migrating my site from Wordpress to Jekyll and I would like to keep the URLs working. My idea was to use a .htaccess file for this and to place it in the root of the site. But unfortunately after trying several tutorials and generates it doesn't seem to work.
The old URLs have the following format
http://example.com/index.php/2016/05/07/title-of-the-blog-post/
The new URLs have this format:
http://example.com/2016/05/07/title-of-the-blog-post.html
Among others I've tried this example which looks good to me, but it actually casues all pages on my site to display an error message :)
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^index.php.*$ http://example.com/ [R=301,L]
I think that should take all URLs that start with example.com/index.php and make them start with example.com/, but apparently that is not the case.
To redirect
http://example.com/index.php/2016/05/07/title-of-the-blog-post/
to
http://example.com/2016/05/07/title-of-the-blog-post.html
you can use the following rule :
RewriteEngine on
RewriteRule ^index\.php/(.+)$ http://example.com/$1.html [NE,L,R]
or alternatively you can use mod_alias like that:
RedirectMatch 301 ^/index\.php/(.+)$ http://example.com/$1.html

URL Rewriting using mod_rewrite

i'm trying lear to make a simple url rewrite and can't understand why is not working.
I created the file .htaccess with this:
RewriteEngine On
RewriteRule ^section\.php$ /how-does-it-work/ [R]
All i want to do is /section.php be displayed as /how-does-it-work/
i'm following a tutorial but doesn't seem to work.
Nothing seems to work… i even tried a mod_rewrite generator, i'm using GoDaddy, is there anything i should activate or something? 'cause so far i'm only dealing with the .htaccess file.
Thanks
You are using them the wrong way around. Try:
RewriteRule ^how-does-it-work/?$ /section.php [L]

.htaccess Removing ampersand from URL?

I have been banging my head against a wall for a long time trying to figure out how to get rid of the last part of some of the URL's on my site. For example, I would like to rewrite this:-
http://www.mysite.com/335-protective-wrapping&page=prod
to this
http://www.mysite.com/335-protective-wrapping
There are about 2000 URL's with &page=prod at the end of them which I need to remove. Here's some more example URL's
http://www.mysite.com/335-protective-wrapping&page=prod
http://www.mysite.com/455-bubble-bags&page=prod
http://www.mysite.com/150-specialist-tapes&page=prod
I have tried many solutions but haven't come up with anything that works.
Any help would be much appreciated.
Thanks.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteRule ^([^&]+)&page=prod$ /$1 [L,R=301]
This should work:
RedirectMatch 301 ^/(.*)&page=prod$ http://www.mysite.com/$1
If you really want to take into account the query part (after the ?) of the source-URI you have to use RewriteCond plus RewriteRule, you cannot just use RewriteRule.
(http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritecond)
Sorry, anubhava, that wont work for that reason.

301 redirect rule in htaccess

What am i doing wrong? this rule isn't working
I want the xyz-banking(old) to xyzbanks(new)
RewriteRule ^category/xyz-banking/?$ http://www.domainname.com/category/xyzbanks/ [L,R=301]
When there are multiple categories goes to one new category...can i do this?
RewriteRule ^category/(chicos|chs|rl)/?$ http://www.domain.com/category/apparel/ [L,R=301]
Ofcourse that one is also not working.
Both rewrite rules seem to be correct and they should work.
Whenever you browse to: http://www.domain.com/category/chs/ you will be redirected to http://www.domain.com/category/apparel/ as requested, etc.
Maybe you have a problem somewhere else:
Is mod_rewrite enabled?
Make sure you have RewriteEngine On on your .htaccess or site configuration.
If using an .htaccess file, Make sure you have an AllowOverride directive that allows you to use RewriteRule there.
Try a simple redirect rule first!
Check your error and access logs to see if you can spot any error or warning message.
Take a look at the URL Rewriting Guide - Apache HTTP Server

PHP Rewrite Rules

The actually URL which my app uses is:
http://site.com/search.php?search=iPhone
but I would like it to be possible to achieve the same with
http://site.com/iPhone
I have no experience of rewrite rules, how can I set this up?
The solution has worked but the new URL is displayed in the address bar. I thought it would have been possible to set this up so that it appears as though the page location is
http://site.com/iPhone
without changing to display
http://site.com/search.php?search=iPhone
Is this possible? Thanks.
Create a file called .htaccess in the root of your website and put this in it.
RewriteEngine on
Options +FollowSymlinks
RewriteBase /
RewriteRule ^(.*) search.php?search=$1 [R]
Should do the trick.
I would suggest however that you make it a bit more specific, so maybe require the user of a search directory in your url. eg instead of mysite.com/IPhone use mysite.com/search/IPhone which would work like
RewriteEngine on
Options +FollowSymlinks
RewriteBase /
RewriteRule ^search/(.*) search.php?search=$1 [R]
This makes it easier to have normal pages that arnt redirected, such as about us or a basic homepage.
As Chris says, this is not PHP but Apache that does this, and whether it works can depend on your hosting setup.
You need to specify something like this in your .htaccess file:
RewriteEngine on
RewriteRule /(.*) /search.php?search=$1
Check also:
mod_rewrite: A Beginner's Guide to URL Rewriting
Module mod_rewrite, URL Rewriting Engine
Rewrite rules aren't part of PHP as far as I'm aware, but Apache (specifically mod_rewrite) or whatever server you're using. For Apache, you need on the server to have a file called .htaccess, and in it put something like:
RewriteEngine on
RewriteRule ^(\w+)/?$ /index.php?search=$1
^(\w+)/?$ is a regular expression - it matches any word of 1 or more characters, followed by a / maybe. So it changes site.com/iPhone into site.com/index.php?search=iPhone. Sound about right?

Resources