Remove directory on dynamic links with .htaccess - .htaccess

I wrote the following codes with .htaccess
RewriteRule ^articles/([0-9a-zA-Z-_]+)$ page.php?article_seolink=$1 [NC,NE,L]
And I created the following URL address
example.com/articles/article-title
But I want to create a link like
example.com/article-title
How can I do this and redirect old URL to new one?

With your shown samples, please try following rules. Please make sure to place your htaccess Rules file inside articles folder. Please make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteRule ^([0-9a-zA-Z-_]+)$ page.php?article_seolink=$1 [NC,NE,L]

Related

Htaccess and redirect all content of folder, but exlude the main folder

I got the following urls:
domain.com/categoryA/articleA
domain.com/categoryA/articleB
I want to redirect:
domain.com/categoryA/articleA -> domain.com/categoryB/articleA
domain.com/categoryA/articleB -> domain.com/categoryB/articleB
but leave it as it is and do not redirect the main folder: domain.com/categoryA/
I tried to use the rule:
RewriteRule ^categoryA/(.*)$ /categoryB/$1 [R=301,NC,L]
but it also redirect domain.com/categoryA/ to domain.com/categoryB/
How to exclude from the above rewrite rule the redirection of the main folder (categoryA), but still redirect all that is in the folder (and then change also the root folder)?
I am looking for a solution that is SEO friendly (I got the same articles in two categories, but want still to have indexed domain.com/categoryA, but the rest only as domain.com/categoryB/xxx.
Best Greetings,
Mat
With your shown samples/attempts, please try following Rules in your .htaccess file. Please make sure to place this rule under your domain redirect rule(if its there), also make sure to clear your browser cache before testing your URLs.
RewriteRule ^categoryA/([\w-]+)/?$ /categoryB/$1 [R=301,NC,L]

htaccess URL rewrite issue - permalinks

I am having some issues trying to prettify some URL's. Basically I need to make this URL http://domain.com/actualfolder/fakepath/this-is-the-article.php to display content from this page http://domain.com/actualfolder/articlemanager.php.
The articlemanager.php is setup to receive a GET url variable in the way of the "this-is-the-article" and search for it in the database. If found, it will display content specific to that result. This part works.
The part that i can't make it to work is the htaccess rule.
This is my rule but it returns 404 not found or 500 if i don't use the initial slashes.
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^fakepath/([^/.]+).php$ articlemanager.php?permalink=$1 [L]
I could really use some help, so any suggestion is welcome.
EDIT: the htaccess file lies in the domain.com/actualfolder/ location

Remove portion from URL using htaccess

My site is having following url
domain.com/ldr1/site/index/category/fashion
and I want like
domain.com/ldr1/fashion
there should be no changes in the functionality.
At the top of your htaccess file in your document root:
RewriteRule ^ldr1/site/index/category/(.*)$ /ldr1/$1 [L,R]
That will make the URL look like domain.com/ldr1/fashion.
Now, whether or not the resource at /ldr1/fashion exists or not is an entirely different issue.

How to perform htaccess rewrite

Here is the summary of my problem.
I have created a Facebook like button. It works correctly most of the time, however not when following the link from somebody's actual "like" post. It seems that Facebook is adding some more info to the URL. For instance, I have
www.example.com/blog.php/6
but Facebook adds
www.example.com/blog.php/6?fb_action_ids=10201090685057512&fb_action_types=og.likes&fb_source=aggregation&fb_aggregation_id=288381481237582
When a user follows this link they get a Mysql syntax error. If they follow the first link there is no problem. I thought I could just strip off all that extra text from the URL.
I created a .htaccess file and placed it in my root directory on GoDaddy.
I Tried several different rewrites.
Nothing has worked. This is the latest thought I tried:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*&)?fb_action_ids=
RewriteRule ^(.*)$ $1?%1 [R=301]
Do I need to change my .htaccess file or is there another way to solve this problem?
Thanks for the help.

Website pages with slashes

Just building a site using php. I would like to know how to create pages without having to make ".php" links for every page. For example I want to build the site to be as follows: www.mysite.com/products instead of www.mysite.com/products.php. (Further example www.mysite.com/products/headphones )
An example of what I am looking for is as follows: http://www.starbucks.ca/store-locator
Any idea how starbucks is doing this? It isn't making a separate folder and index for every page is it?
Thanks in advance!
Jason
You can use URL rewriting to do this. You can create a .htaccess file, place it in the root directory of your website with the following content (as an example):
RewriteEngine On
RewriteRule ^tutorial/([0-9]+)/$ index.php?tutorial=$1
RewriteRule ^page/store-locator/$ index.php?page=store-locator
RewriteRule ^$ index.php
These are some basic rules that tell the web server to rewrite a URL without .php to a URL that does have .php.
In the above example, when you are visiting example.com/tutorial/3/, it will actually visit example.com/index.php?tutorial=3 and then your index.php will display the contents. It's similar for the store-locator page.

Resources