Remove folders from url using .htaccess issue - php

Hi So I am trying to remove includes/pagesfrom a url that looks like http://localhost:8888/london/includes/pages/soho-london-guide/ For local dev. I am using MAMP and I've enabled mod_rewrite too.
So far I've been trying to use different techniques and here is a list of what I've been using (trying to make it work :((( )
RewriteEngine ON
RewriteRule ^includes/pages/(.*)$ $1 [L,QSA]
Also
RewriteEngine on
RewriteBase /
RewriteRule ^/includes/pages/(.+)$ /$1 [L,QSA]
Very very new to .htaccess and regex syntax so any help would be appreciated.

Have this rule in your site root .htaccess:
RewriteEngine on
RewriteBase /
RewriteRule ^([\w-]+)/(?!includes/pages/)(.+)$ $1/includes/pages/$2 [L,NC]

Related

htaccess rewrite rule knowledge

I want to rewrite the url of mysite with help of htaccess. My website url which I need to rewrite is given below.
http://getallfreedownloads.com/category.php?slug=business_directory_listing
Result needed
http://getallfreedownloads.com/business_directory_listing or http://getallfreedownloads.com/business_directory_listing/
I have used the below code for rewrite rule in my htaccess file
RewriteEngine On
RewriteRule ^([^/]*)$ /category.php?slug=$1 [L]
Please guide me what I can do to make it work fine.
Note: After adding rewrite rule I have removed the " category.php?slug= " from the a Tag
I will be thank full to you all.
try this once.
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^/category.php?slug(.*)$ /$1 [L,NC,R]

Use Mod Rewrite to change site URLs [duplicate]

This question already has answers here:
Url rewriting mod_rewrite
(3 answers)
Closed 6 years ago.
Im pretty new to Apache's mod_rewrite and I'm trying to change how my URLs are displayed in the address bar. For instance I want
www.example.com/index.php
to be
www.example.com/home
and
www.example.com/products.php
to be
www.example.com/products
and so forth. So far I have this in mind but it's not working
RewriteRule ^home$ /index.php [L]
You need to do the following:
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.example.com/home/$1 [R=301]
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.example.com/products/$1 [R=301,L]
You can either put this on httpd.conf in apache or in .htaccess file.
L means - Last - stop processing rules
You can try this. Edit the .htaccess file contents as:
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
</IfModule>
This will redirect an url like this: example.com/any_path.php to example.com/any_path. To be precise, you are removing the .php extension from any PHP file.
Note:
For specific url, replace ([^\.]+) in the RewriteRule with the text.
Specify a correct path for RewriteBase in case you are using a subdirectory.
mod_rewrite should be turned on for your server system. Google a bit for turning on mod_rewrite in your system.

Opencart SEO rewrite 404 error

I am working for someone who runs a webshop. Now the webshop runs on Opencart software, and fortunately they support SEO Url rewriting. I have been trying to get this working for the last 2 hours and havent been able to get it right. I have done the following to the .htaccess file.
# 1.To use URL Alias you need to be running apache with mod_rewrite enabled.
# 2. In your opencart directory rename htaccess.txt to .htaccess.
# For any support issues please visit: http://www.opencart.com
Options +FollowSymlinks
# Prevent Directoy listing
Options -Indexes
# Prevent Direct Access to files
<FilesMatch ".(tpl|ini|log)">
Order deny,allow
Deny from all
</FilesMatch>
# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/
RewriteBase /opencart/
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
Additionally i have enabled SEO rewriting on opencart and given all products/categories etc. a SEO name.
Now the .htaccess file is located in: public_html/opencart/ so i have changed the RewriteBase from / to /opencart/
Still i get the following errors:
Not Found
The requested URL /aquaria/adm-aquaria was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Does anyone have a solution for me?
To give you an example i want the following link: http://aquadeco.eu/index.php?route=product/category&path=94_291 to look like this: http://aquadeco.eu/aquaria/adm-aquaria
You don't have to put this
RewriteBase /opencart/
If your url are like this yourDomain.com/opencart/index.... Then
you will have to put RewriteBase /opencart/
end if; :)
with your url you don't have to put RewriteBase /opencart/
only /
Regards
Ok, wow i just found out i have been stupid the whole time. I had 2 .htaccess files. One which was the original without the right rewrite rules and 1 in my /opencart/ folder which had the right rewrite rules. What i did now is put the right rewrite rules into the .htaccess file in my root folder and it fixed the problem!! :D
You put your site in sub directory so you have to make following changes
RewriteBase /opencart/ change to RewriteBase /
and
RewriteRule ^([^?]*) index.php?route=$1 [L,QSA] change to
RewriteRule ^([^?]*) /opencart/index.php?route=$1 [L,QSA]

how to rewrite wp-admin url to some other folder using htaccess?

I tried to rewrite a simple RewriteRule but i guess it doesn't turn up good. I created a htaccess file in wordpress wp-admin folder and i tried to rename the wp-admin directory name in my localhost.Here is the code i tried
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^wp-admin$ hello
Just for testing i had done this in my localhost. I want to start from simple pattern not complex pattern so i tried other simple pattern wp-admin and replacement as hello
RewriteEngine On # Turn on the rewriting engine
RewriteRule wp-admin hello
When i go to http://localhost/my_site/hello i can't able to direct to wp-admin for this am getting 404 error. When i try http://localhost/my_site/wp-admin am getting internal server error.
I think the rewrite rule is not good in my try. I have one more doubt should place the .htaccess file in the wp-admin directory or in the my site root directory in my_site or should i place in every directory which am trying to change the folder name on the fly.
What wrong am i doing here.Any help please?
RewriteRule ^hello(.*)$ wp-admin$1 [QSA]
Will change:
http://yourdomain.com/yourwp/hello
http://yourdomain.com/yourwp/hello/path/in/admin
to
http://yourdomain.com/yourwp/wp-admin
http://yourdomain.com/yourwp/wp-admin/path/in/admin
The QSA flag is useful for compatibility.
Here is my wordpress .htaccess with only one custom redirect, but you can understand the idea:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^login/?$ /wp-login.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

SEO friendly url in PHP htaccess

I use Godaddy Apache server to build my own blog, and I did some search of SEO friendly url tutorials, and applied the following code in my web root .htaccess file to transfer links like http://www.bgmemo.com/blog.php?url=2012/08/23/4-steps-to-initialize-Apache-Derby-10-9-1-0-in-Netbeans-7-1-1.html to http://www.bgmemo.com/blog/2012/08/23/4-steps-to-initialize-Apache-Derby-10-9-1-0-in-Netbeans-7-1-1.html :
RewriteEngine on
RewriteRule ^([a-zA-Z0-9-/]+).html$ blog.php?url=$1
RewriteRule ^([a-zA-Z0-9-/]+).html/$ blog.php?url=$1
But it does not work. The htaccess is working and other code in it is applied. Who can tell me what is wrong? Thanks in advance.
Try this:
RewriteEngine on
RewriteBase /
RewriteRule ^blog/([a-zA-Z0-9\-/\.]+)/?$ blog.php?url=$1 [L]
This is the correctly way for donĀ“t have problems with your .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^blog/([a-zA-Z0-9\-/\.]+)/?$ blog.php?url=$1 [L]
</IfModule>

Categories