i have a problem with trying to redirect urls in a htaccess file
I am trying to redirect from this url below, (u=6 will be random numbers)
index.php?action=profile;u=6
to
index.php?action=pm
RewriteEngine on
RewriteRule ^index.php?action=profile;u=/([^/]*)$ index.php?action=pm
I have tried lots of different varations but I can not seem to get it to work
I have the app installed under the directory
/messages
I tried making all the changes to the htaccess file in both the /root and /messages directory, but to no aval, any help would be grateful, thanks in advance for your time
Try with:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^action=profile;u=\d+ [NC]
RewriteRule ^index\.php$ index.php?action=pm [NC,L]
Try this:
RewriteRule ^index.php\?action=profile;u=([0-9])+$ index.php?action=pm
Related
I've made some search about .htaccess Rewrite function, but I couldn't find any example with an html reference.
I'm trying to redirect from my example.com/products/category/ link to another page.
Here's the link what I'd like the .htaccess file to redirect:
<a href="example.com/products/category/?category=bathroom">
I'd like to achieve this style:
example.com/products/category/bathroom/
Here's my .htaccess ReWriteRule:
RewriteRule ^products/([A-Za-z0-9-]+)/?$ /products/category.php/?category=$1 [L] # Process category
Note that I'm using two different php pages for both. page-category.php and category.php
I've places it after
RewriteEngine On
RewriteBase /
but still it doesn't work.. The only time something happened when I tried some combinations, it threw back an internal server error. Is there a problem with my RegEx or am I not doing the linking right ?
EDIT: I'm using wordpress, I forgot to mention that, sorry.
You need to use Redirect 301
RedirectMatch 301 ^example.com/products/category/?category= /example/home/page-category.php
Or you can use mod_rewrite instead:
RewriteEngine On
RewriteRule ^example/products/category/?category= /example/home/page-category.php [L,R=301]
same you can do for another file.
as i understood from your question you need something like this in category directory .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) category.php?category=$1 [QSA]
Now anything that is not a directory or a file inside category directory will be rewriten like /category/bathroom will be rewriten to (without redirection) /category.php?category=bathroom
i have following htaccess file which redirecting every link to /love/tribe-world directory (including root also).
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (?!^/campaigners/)^(.*)$ /love/tribe-world/campaigners/$1 [L,QSA]
i have written above rules for hiding /love/tribe-world directory from url. i wanted url www.example.com/campaigners/start-process instead www.example.com/love/tribe-world/campaigners/start-process, which is working using above rule.
But its redirecting every request to the /love/tribe-world which is strength for me.
Can anyone guide me what i am doing wrong here...
Thanks in advance
Your lookahead is incorrect. Use this rule:
RewriteEngine on
RewriteRule ^(campaigners.*)$ /love/tribe-world/$1 [L,NC]
I am currently trying to figure out how to create an htaccess file that will allow me to perform the following, however I have searched everywhere, and on stackoverflow but I cannot find a solution.
I have an existing site, with a directory /brands/, and an htaccess file setup so that putting anything after brands e.g. /brands/diesel redirects to /brands/index.php?brand=diesel. What I now need to do is redirect anything further in the URL to a seperate page ( in the same directory ), for example /brands/diesel/jeans/male will redirect to inner.php?sear=diesel&t=jeans&g=male
I have tried the following with no success:
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ inner.php?sear=$1&t=$2&g=$3 [L]
Anyone who is competent at writing htaccess files will probably be able to spot what is wrong immediately, but unfortunately I am not great with these.
Any help would be greatly appreciated.
I think you might have to setup RewriteBase.
RewriteBase /brands/
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ inner.php?sear=$1&t=$2&g=$3 [L]
Try these rules
RewriteEngine On
RewriteBase /brands/
RewriteRule ^([^/.]+)/([^/]+)/([^/]+)/?$ inner.php?sear=$1&t=$2&g=$3 [L,QSA]
RewriteRule ^([^/.]+)/([^/]+)/?$ inner.php?sear=$1&t=$2 [L,QSA]
RewriteRule ^([^/.]+)/?$ inner.php?sear=$1 [L,QSA]
I have a custom web app and the file structure works like this:
/apps/calendar/frontend/index.php
/apps/calendar/frontend/view/index.php
/apps/calendar/backend/index.php
/apps/calendar/backend/edit/index.php
/apps/calendar/backend/add/index.php
/apps/calendar/backend/view/index.php
I'm trying to write a .htaccess file to help redirect the files so they cant see the 'real' path.
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/admin
RewriteRule ^([^/\.]+)/(.*)/(.*)($|/$) /apps/$1/frontend/$2/$3 [NC,L]
RewriteRule ^([^/\.]+)/(.*)($|/$) /apps/$1/frontend/$2 [NC,L]
RewriteRule ^([^/\.]+)($|/$) /apps/$1/frontend/ [NC,L]
When I visit localhost/calendar it should map redirect to /apps/calendar/frontend/index.php. But when I visit localhost/calendar/add it gives me a 301 (permanent move) then shows the full page of localhost/apps/calendar/frontend/add/index.php in the console. Anyone got any ideas why this would happen? Or a better way around this? The apps might have heaps of sub-directories so, I'm not particularly keen on having a rule for ever subdirectory combination.
As you can see also I have a /admin path, which would load the /backend/ parts of the app. I would assuming I can do the similar code with the prefix of /admin?
This question might also be of your interest: Create blog post links similar to a folder structure.
Given that your .htaccess is located on the root folder of your domain /home/youraccount/public_html/.htaccess, it would look like this:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/(admin|apps) [NC]
RewriteCond %{DOCUMENT_ROOT}/apps/$1 -d
RewriteRule ^([^/]+)/?(|.*)$ /apps/$1/frontend/$2 [NC,L]
RewriteCond %{REQUEST_URI} !^/apps [NC]
RewriteCond %{DOCUMENT_ROOT}/apps/$1 -d
RewriteRule ^admin/([^/]+)/?(|.*)$ /apps/$1/backend/$2 [NC,L]
Let's say the user access:
http://domain.com/calendar
http://domain.com/calendar/
http://domain.com/calendar/add
All the above would redirect to
/apps/calendar/frontend/index.php
/apps/calendar/frontend/index.php/
/apps/calendar/frontend/index.php/add
And the if the user access:
http://domain.com/calendar/admin
http://domain.com/calendar/admin/
http://domain.com/calendar/admin/add
It would go to:
/apps/calendar/backend/index.php
/apps/calendar/backend/index.php/
/apps/calendar/backend/index.php/add
So it would make index.php your controller for each end:
/apps/calendar/frontend/index.php
/apps/calendar/backend/index.php
I've got troubles with .htaccess, I know there are similar posts, but I cant figure out even with them.
I need my webpage to relocate user from url like
website.net/photos?action=something
to
website.net/?fotky=something
Thanks for all
Try adding the following to the .htaccess file in the root directory of your site.
RewriteEngine on
RewriteBase /
RewriteCond %{QUERY_STRING} (^|&)action=([^&]+)(&|$) [NC]
RewriteRule ^photos$ ?fotky=%2 [NC,L,R=301]