Directory rewrite URL in Apache, htaccess - apache

I urgently need help in rewriting php URLs for my site. I have researched and tried everything but it's still not working.
I want to rewrite all the URLs in my htaccess file to rename the directory '_public' to 'art':
www.site.com/_public/work.php
so all url's show:
www.site.com/art/work.php
Can anyone help? would appreciate it very much.

If I understand correctly, you want the user to go to 'www.site.com/art/work.php' and get the page located at 'www.site.com/_public/work.php' displayed.
In .htaccess (in the root directory) do:
RewriteEngine on
RewriteRule ^art/(.+)$ /_public/$1 [L,QSA]

Please add below lines in your htaccess file:
RewriteEngine on
RewriteRule ^art/(.+)$ /_public/$1

Related

htaccess regex redirect

I am trying to redirect from source url to target url using regex but it didn't work. Here i describe my problem -
Source URL:
http://example.com/forums/forum/lisa-goran-bygger-hus-t5075/
Target URL:
http://example.com/forums/details/lisa-goran-bygger-hus/
want to redirect without -t5075 from url.
htaccess rewrite rule is:
RewriteRule ^/forums/forum/([a-z-]+[^-t0-9]) /forums/details/$1 [R=301,L]
this isn't work its redirect to me -
http://example.com/forums/details/lisa-goran-bygger-hus-t5075/
Here regex online tester link -
http://www.regextester.com/?fam=97698
What i am doing wrong can someone help me out and explain about this problem.
Thanks
First, make sure mod_rewrite is enabled and htaccess files allowed to be executed.
Then, make sure .htaccess file is in root folder and look like this
RewriteEngine On
RewriteRule ^forums/forum/(.+)-t[0-9]+/$ /forums/details/$1/ [R=301,L]
Finally, try clearing your browser's cache. Indeed, your old rules could interfere. After that, it should work.

Apache invisible URL Rewrite to subdirectory

I want to use URL Rewrite to rewrite all requests on my domain to a subdirectory. But the visitor hould not see, that it is a subdirectory. I tried a view things, but nothing worked really good. Can you help me? In this subdirectory is also a .htaccess file and this file shouldn't be ignored by the server.
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteRule (.*) sub-directory/$1 [L]

301 redirect not working

I made a subdomain, and I am trying to redirect a page from the original domain to the subdomain, with the same dir structure.
My original page is this:
http://www.comehike.com/outdoors/alaska_hiking.php
I put this rule into the .htaaccess file under comehike.com/outdoors/ directory:
RewriteRule ^outdoors/alaska_hiking.php http://hiking.comehike.com/outdoors/alaska_hiking.php [R,L]
But as you can see from visiting the original url, it doesn't redirect. Any idea why?
Thanks!
I use apache server.
That RewriteRule line works for me when I stick it in my .htaccess file, are you sure you have RewriteEngine On?

the .htaccess is not working

I'm trying to write a simple .htaccess rule to change
https://webxxx.example.net/~test/id/123
to
https://webxxx.example.net/~test/show.php?id=123
But
https://webxxx.example.net/~test/id/123
is now redirected to my 404 page not found.
my .htaccess:
RewriteEngine on
RewriteRule ^\/?~test\/id\/(\w+)$ /~test/show.php?hash=$1
Why doesn't this work?
The solution:
don't need match the reference of public_html folder in regular expression, only in replace
RewriteEngine onRewriteRule ^id\/(\w+)$ /~test/show.php?hash=$1
thanks to all :)
where is the .htaccess placed ? is it under the main root ? or is it under the subfolder (subdomain) ... try to change the place of the .htaccess and make sure it is under the specific subdomain area .
I think this is what you want:
RewriteEngine on
RewriteRule ^id\/([0-9]*)$ /~test/show.php?id=$1
This will just accept numbers after the id.

apache url rewrite on .htaccess

I need to figure out the code on my .htaccess for the following.
Redirect url http://www.mydomain.com/somekw to http://www.mydomain.com/differentkw
also http://www.mydomain.com/somekw?sort=rating&order=ASC to http://www.mydomain.com/differentkw
I have read up about .htaccess but I have very little skills, hopefully someone can help me out.
This should work:
RewriteEngine on
RewriteRule somekw differentkw [L]
That will change any instance of somekw of differentkw. The GET values will stay there.
Just make sure you have mod_rewrite enabled.