mod rewrite %2F in url - .htaccess

I have this url:
http://www.mydomain.com/search.php?title=beatiful%2Fcat
I need rewrite it to:
http://www.mydomain.com/beatiful+cat
I added this line in my .htaccess:
RewriteRule ^([^/]*)$ /search.php?title=$1 [L]
but without success.
Thanks in advance!

If you added:
RewriteRule ^([^/]*)$ /search.php?title=$1 [L]
to your htaccess file in your document root, and there aren't any other rules before it, then you shouldn't be getting a 404, you should be getting a 500 internal server error because these rules will loop infinitely.
This means either your htaccess file isn't being read or you don't have FILEINFO override rights in whatever directory the htaccess file is in.

Related

Redirect folder with data

hi i read all of other questions but i cant resolve my problem.
i setup my joomla website in this url: https://www.example.com/new
and now i want reditect this to (https://www.example.com) with my data for example i want reditect example.com/new/all-ads-smart/103-Hotels or other to example.com/all-ads-smart/103-Hotels
also i test this but it dont work
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^new/(.*)$ https://www.example.com/$1 [R=301,L]
this just work when i open (https://www.example.com/new) and redirect me to (https://www.example.com) and when open this (https://www.example.com/new/ads.php) i give 404 error
in end i sorry for my bad english<3
my data is:
new/all-ads-smart/103-Hotels
to
/all-ads-smart/103-Hotels
RewriteRule ^new/(.*)$ https://www.example.com/$1 [R=301,L]
This actually looks OK and should "work", providing it is in the root .htaccess file and located near the top of that file. However, if you still have a .htaccess file in the /new subdirectory then this is likely to override the directive in the parent .htaccess file - so it won't do anything.
However, it would be preferable to do this in the /new/.htaccess file instead (and keep the parent .htaccess file clean). For example, remove everything in the existing /new/.htaccess file and simply have an unconditional redirect:
RewriteEngine On
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
This will override the parent .htaccess file and when anyone visits the /new subdirectory they will be redirected. (This uses mod_rewrite, as opposed to a mod_alias Redirect to ensure that it overrides the parent .htaccess file.)

Friendly url pagination

I am new on that htaccess thing.
My problem is, I have a pagination on index.php:
http://localhost/index.php?pagina=2
I want to access this with this url:
http://localhost/page/2
I try on htaccess:
RewriteEngine On
RewriteRule /page/(.*)$ index.php?pagina=$1
but it gave me a 404 error.
In per-directory .htaccess files the directory prefix, of where this .htaccess file is located, is removed from the URL-path when pattern matching. In the document root, this is simply / (a slash). So your RewriteRule would need to be rewritten as:
RewriteRule ^page/(.*) /index.php?pagina=$1 [L]
Use:
RewriteEngine On
RewriteRule page/(.*)$ index.php?pagina=$1
without first /

Why my htaccess rule is not working unless it's directed to a PHP file

My htaccess file is under "myappname" folder.
I'm trying to redirect this path;
myappname/CONTROLLER_NAME/ANYFILE.(css|js|gif|jpg|png)
To that path
myappname/views/default/tpl/CONTROLLER_NAME/ANYFILE.(css|js|gif|jpg|png)
and this is my HTACCESS rule
RewriteEngine on
RewriteRule ^(.*)/(.*)\.(css|js|gif|jpg|png)$ views/default/tpl/$1/$2.$3 [L,NC]
but it's giving me HTTP 500 unless I redirect it to a PHP file like
RewriteEngine on
RewriteRule ^(.*)/(.*)\.(css|js|gif|jpg|png)$ views/default/tpl/$1/index.php?a=$2.$3 [L,NC]
What is wrong with my rule? I'm very new to htaccess and there is a very big potential to I'm missing something small.
This is because your target matches the regex:
views/default/tpl/foo/bar.png
matches the regex:
^(.*)/(.*)\.(css|js|gif|jpg|png)$
So the rules just keep looping. You need to add a condition:
RewriteCond %{REQUEST_URI} !^/views/default/tpl
right above your RewriteRule.

.htaccess rewrite resulting in 404 error

I am trying to create search engine friendly URLs with the following .htaccess and it is directing to a 404 error page no matter what I try.
This is on a Host Gator shared account, if it makes any difference. The directory is (document root)/blog, the .htaccess file is located in the directory "blog."
Example URL would be http://examplesite.com/blog/category/announcements.Here is the .htaccess file contents:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^category/([a-zA-Z0-9]+)/$ index.php?category=$1
Any ideas why this is happening?
RewriteRule ^category/([a-zA-Z0-9]+)/*$ index.php?category=$1 [R=301,L]
Forget the preceeding slash?
RewriteRule ^category/([a-zA-Z0-9]+)/$ /index.php?category=$1

HtAccess Rewrite Needed

My host will not allow me to change the default folder of my primary domain. I have managed to Rewrite http://www.mysite.com to the real folder
public_html/mysite.com/www/
with the following code:
RewriteEngine On
RewriteRule ^$ /mysite.com/www/ [R=301,L]
This does successfully load my domain from the subfolder, but the url becomes:
http://mysite.com/mysite.com/www/
How can I continue loading requests from http://mysite.com/index.html in the correct folder shown above, without showing it in the client-side url?
Try this one:
RewriteEngine On
RewriteRule ^mysite.com/www/(.*) - [L]
RewriteRule ^(.*)$ mysite.com/www/$1 [L]
UPD:
The line with the dash is required because after the redirect at line 3 Apache reads the .htaccess once again to process the redirected URL. The rule prevents infinite loop.
Try removing the R=301.

Resources