I want to change URLs in one folder (cartoon) in my site to friendly SEO URLs.
This folder (cartoon) includes a PHP script not related to WordPress.
From:
example.com/cartoon/index.php?v=TitleEpisode
To:
example.com/cartoon/TitleEpisode
I read here all related questions but I did not benefit.
I have WordPress on my main domain (example.com).
I found this code in .htaccess file:
DirectoryIndex index.html index.php index.htm parking-page.html
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
What do I do?
Ok, based on the edit, it seems like what you want is for WordPress not to rewrite that slug but to ignore it.
You can do this by editing your .htaccess to exclude a folder. Make sure the folder is in the root directory of your site, as in, the same folder as wp-admin, wp-content, and wp-includes.
Then, open your .htaccess and add a rewrite rule to ignore that folder:
DirectoryIndex index.html index.php index.htm parking-page.html
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# Add this condition with the folder you want to ignore (cartoon in your example)
RewriteCond %{REQUEST_URI} !^/(cartoon|cartoon/.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
OLD ANSWER
Well, this is fairly open-ended. For a better answer, please edit the question to include what you have already tried. Also, what do you mean by "one folder"? Is this a custom post type? Is it a category or custom taxonomy? Are there different permalinks for different types/taxonomies? Please provide more details on what you want to do.
But for the usual case, here is the documentation for pretty permalinks.
First, make sure URL Rewriting is enabled in Apache. Example in Ubuntu/Debian
sudo a2enmod rewrite
sudo service apache2 restart
Now, in wp-admin, go to Settings -> Permalinks. Set the permalink to Post Name.
Then click save changes. It will either save the new .htaccess automatically if your site has the permissions to, or it will give you the new content of .htaccess to copy and paste.
Now you should be able to view a post or page and it should show the SEO-friendly links.
How are you implementing (or intending to implement) the routing of example.com/cartoon/TitleEpisode?
If this is entirely outside of WordPress then I would expect you to have an additional .htaccess file inside the /cartoon subdirectory (since this is presumably a physical subdirectory)? This alone should be sufficient to override the WordPress mod_rewrite directives in the parent .htaccess file, since mod_rewrite directives are not inherited by default.
For instance, simply enabling the RewriteEngine in a subdirectory is sufficient to override the WP directives.
In /cartoon/.htaccess:
RewriteEngine On
Then, in order to route a URL of the form /cartoon/TitleEpisode to /cartoon/index.php?v=TitleEpisode, you would need something like:
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ([^/]+) index.php?v=$1 [L]
(A bit similar to the WP directives in the parent .htaccess file.)
I would avoid editing between the # BEGIN and # END WordPress markers in the parent .htaccess file since these could be overridden by future WP updates.
You would instead implement an exception before the WP directives. For example:
RewriteRule ^cartoon - [L]
However, as mentioned above, you are probably better off creating an additional .htaccess file in the subdirectory and avoid touching the WordPress installation at all.
it's done.
i enter this after the first line in .htaccess
# BEGIN for Cartoon Folder
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?cartoon/(.+)$ /cartoon/?v=$1 [L,QSA]
# END for Cartoon Folder
thank u very much
Related
I'm a new user and frankly, I haven't got a clue what I'm doing at this point. I'm figuring things out slowly but surely and this site has so far been a gold mine for me... So, let's see if we can make this work.
So, my website has a WordPress installation within the root directory to allow me to have a blog; WordPress is installed solely for the blog and this is in the public_html/wp folder. Everything within the wp folder is WordPress.
Now, when I write a post, the permalink is my-website.co.uk/wp/post-title.
The .htaccess file rewrites this permalink to my-website.co.uk/blog/post-title.
This is great, looks much better but the problem is, when WordPress auto-shares the posts, the /wp/post-title permalink redirects to homepage and not to the relevant blog post. This means, whenever someone clicks on the shared link, they're taken to my homepage (sorry if I sound like I'm dumbing it down).
Now, in the public_html folder, I have one .htaccess file which is as follows
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^(.+?)/do-not-touch.php do-not-touch.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.htm -f
RewriteRule ^(.+?)/?$ $1.htm [L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule .*[^/]$ $0/ [L,R=301]
RewriteRule ^blog/([0-9-]+)/?$ blog.php?page=$1
RewriteRule ^blog/([A-Za-z0-9-]+)/?$ blog.php?slug=$1
RedirectMatch 301 ^/tenants.htm /information-for-tenants.htm
Then, in the WP folder, we have another .htaccess file:
#+PHPVersion
#="php70"
AddHandler x-httpd-php70 .php
#-PHPVersion
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wp/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wp/index.php [L]
</IfModule>
# END WordPress
My theory (remember, I have no idea what I'm doing) is that the second .htaccess file redirects the /wp/ permalinks up to the public_html file index (shown by the RewriteBase /wp/ RewriteRule ^index\.php$ --- Not sure what the \.php$ does) whilst the first .htaccess file rewrites the /wp/post-title to /blog/post-title (shown by RewriteRule ^blog/([0-9-]+)/?$ blog.php?page=$1 and RewriteRule ^blog/([A-Za-z0-9-]+)/?$ blog.php?slug=$1).
Finally, in my WordPress admin permalink settings, the selected permalink is shown as my-website.co.uk/wp/sample-post/.
All permalinks are my-website.co.uk/wp/[customisable] -- In other words, it doesn't allow me to alter the /wp/ section of the permalink.
I could really use some help. I need to redirect wp/post-title (whatever the title may be) to blog/post-title instead of /index.
As a result of the redirect, search engines fail to crawl my blog posts (I think?).
This is my website blog: https://www.harryalbertgroup.co.uk/blog
And this is the WP permalink: https://www.harryalbertgroup.co.uk/wp
Thanks in advance.
(Note: This website was built for me. I've been slowly fixing all of the issues I've faced so far. We're slowly getting there, it's really just the sharing features that I need to fix now, from what I can see)
Okay. So I have a site that needs to be live around 8am EST. Everything was going fine, but when I uploaded it to the server my two pages return 404 not found errors. Absolutely everything else on the site is fine.
I have tried several things. I have reset the permalinks several times. I have deleted auto-saved files in the database. I have re-uploaded the database. I have re-uploaded the site. I have set the permission on .htaccess. I have deleted .htaccess and let it rewrite itself. Nothing has worked. Does anyone have any ideas?
The page works when it is set to default, but NOT when it is set to anything else.
Update This is the .htaccess file
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Based on the .htaccess you can make these changes... although this is the default .htaccess for Wordpress it looks like it has an extra slash in front of index.php for the main redirect line. You'll also want to check to make sure that your Virtual Host Apache directory contains AllowOverride All.
In this example we're telling Apache if the request isn't for index.php then see if it's a real file and a real directory, then if it's not show them the default page. This is similar to the default behavior of Wordpress already.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !=index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.* index.php [L]
</IfModule>
# END WordPress
There is also a whole Stack Exchange site devoted to Wordpress at wordpress.stackexchange.com.
This is basically the same question:
https://wordpress.stackexchange.com/questions/11149/htaccess-disable-wordpress-rewrite-rules-for-folder-and-its-contents
In my root wordpress site running
I have the usual wp-content, wp-includes, wp-admin folders, but I also have my 'drupal' which is a drupal site
I have .htaccess file in both root and drupal directory
When i try to access any node of drupal website give page not found error of wordpress
Please a help me for that
Add RewriteRule ^drupal - [L] above the WP rules in the .htaccess that is located in the root.
I have seen this a lot with Cpanel and Fantastico.
https://www.drupal.org/forum/support/post-installation/2010-08-09/installing-wordpress-in-a-sub-directory-of-drupal
The topic is old but still relevant. Just wanted to share my solution to this problem.
In WP, go to Admin > Settings > Permalinks;
Scroll down to the
bottom; You should see this:
If your .htaccess file were writable, we could do this automatically, but it isn’t so these are the mod_rewrite rules you should have in your .htaccess file. Click in the field and press Ctrl+a to select all.
Add this to WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /YOURSUBDIR/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /YOURSUBDIR/index.php [L]
</IfModule>
Open your .htaccess in the Drupal root dir, and find this bit:
# Pass all requests not referring directly to files in the filesystem to
# index.php. Clean URLs are handled in drupal_environment_initialize().
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]
Paste the WP Admin code underneath this, from "RewriteBase" to the end;
It should work now!
Make sure your WordPress permalinks are reset by hitting save ( the first URL here walks you through it
- https://www.cloudways.com/blog/fix-404-error-on-wordpress/
If that will not work try this.
See:
https://www.drupal.org/forum/support/installing-drupal/2007-08-02/the-requested-url-not-found-on-this-server
- I hope this is helpful cloudways.com will know the fix too.
Add this to WordPress
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Ignoring Subfolders that exist in the DocumentRoot
With clean URL's enabled, when running other software applications in subfolders (subdirectories) of a Drupal root installation. your .htaccess file may rewrite those URL's to Drupal. This may be a particular problem for those with a Drupal installation in the root of their domain using Cpanel and Fantastico where Fantastico installs other software into subfolders. For example, phpSurveyor's admin interface as installed by Fantastico will not work with Drupal's default .htaccess settings. The URL for the admin interface is inaccessible and will return a "page not found" page in your Drupal site.
The trick is to modify .htaccess to ignore specific files/folders. So for example, if you have two folders, and in the root of your Drupal installation, modify your .htaccess file by inserting the following code directly after the "RewriteEngine on" directive, before the Drupal rewrites:
=========[ start of .htaccess snippet]==========
<IfModule mod_rewrite.c>
RewriteEngine on
#
# stuff to let through (ignore)
RewriteCond %{REQUEST_URI} "/folder1/" [OR]
RewriteCond %{REQUEST_URI} "/folder2/"
RewriteRule (.*) $1 [L]
#
====================[ end ]=====================
For each folder, you want to bypass, add a RewriteCond line, and end all but the final RewriteCond with [OR]. Note that the [L] in the rewrite rule tells it to stop there and bypass the rest of the rewrite rules.
Ignoring subfolders that are included via Apache Alias directives
As of 4.7, files and directories should be automatically allowed through in drupal's .htaccess setup. Thats what the !-f and !-d lines do.
However if you are working with Apache Alias or similar directives the file doesn't actually exist so drupal will take over like it should. The best way around it is to just add one more conditional that matches your location and make it skip it too. Thats what the ! means. Please see below:
RewriteCond %{REQUEST_URI} !^/yourDirectoryName
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
It essentially means Apply this rule if the REQUEST_URI doesn't start with /yourDirectoryName and the REQUEST_FILENAME isn't a real file or a real folder. Which is exactly what you want. There is an implied "AND" between the lines of that rule. The ! says "not like this".
I am trying to install shopping cart cms "x-cart" in a sub-directory "/store/" on my Wordpress site.
I have permalinks enabled and mod rewrite in htaccess... So when I try to access anything within "/store/" folder i am getting wordpress 404 :(
How do I exclude "/store/" folder in htaccess?
Here is my current one:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Thanks in advance!
If you have a folder called "store" you don't need to do anything. This line:
RewriteCond %{REQUEST_FILENAME} !-d
Is saying that "If the request is from a real directory (-d) ignore this index.php stuff and go with it". So, just create /store and put a "index.html" to see if it isn't an issue with x-cart instead of wp
If you are creating multi WP website, you can consider using WP multisites feature which can be found herecodex.
You might find it easier to either install x-cart on a sub-domain (store.yoursite.com), or just put it in a folder at the same level as wordpress yoursite.com/store.
We have a WP install in the root of our server and its running great.. but, we just installed another app in a subdomain. Now, I can view the index.php of that app but cannot do anything with it.. the htaccess rules in the root (from WP base install) are effecting the requests.
So, how to I eliminate the WP htaccess file from effecting the subdomain?
Here is the htaccess contents for the root (WP install):
<IfModule mod_rewrite.c>
RewriteEngine On
# BEGIN WordPress
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
</IfModule>
And for the htaccess in the subdomain:
RewriteEngine on
RewriteCond $1 !^(index\.php|css|stylesheets|js|images|user_guide|favicon\.ico|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
I've search everywhere online and tried a couple samples I found.. nothing has worked.
Any help is greatly appreciated !
Thanks
UPDATE:
It seems that maybe Wordpress is not the culprit.. out of curiosity, I removed all lines in the WP .htaccess file.. and the app in the subdomain was still not working. Its rewrite rule must be wrong..
So, it is the second rewrite rule that is not working. If I type in /index.php?about then I can see the about page.. but it should display by going to: /about
WP is also the culprit (you have two problems).
I can fix the first .htaccess problem because WP is predictable. You want to put this before the BEGIN WordPress section:
RewriteRule ^subdir-name/.*$ - [PT]
That grabs any requests to your subdir and Passes it Through (PT) so that it is not hijacked by WordPress.
The problem in your second .htaccess is that it seems to be assuming it is still in the root directory. For this one, I can't be sure without seeing the layout of your app, but the / before index.php may well be wrong. Are you sure that the paths in the second file match the new layout of your files?
Um... should this work? For sub-directory "office" - cheers :-)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^office/.*$ - [PT]
# BEGIN WordPress
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
</IfModule>