I have a kind of Joomla and WordPress mashup.
The Joomla site is in the web Root directory (httpdocs directory) and the WordPress site is in a sub directory (jobs subdirectory).
I have a PHP script that uses a long query string placed in the WordPress directory:
http://example.com/jobs/search.php?search=true&auth=AUTHCODE&skills=developer&andor=OR×cale=6&areas=&andor_areas=OR&posted=1
I would like this to be rewritten to something like:
http://example.com/jobs/search/true/AUTHCODE/developer/OR/6//OR/1
I have tried many mod_rewite rules using the mod_rewrite generators online and they do not work. I get "page not found" from the standard WordPress warning.
I have tested mod_rewite rules both in the Joomla .htaccess file and the WordPress .htaccess file.
I have tried various different combinations of the code below using:
RewriteRule ^/jobs/cvsearch/
or
RewriteRule ^cvsearch/
or
RewriteRule ^/cvsearch/
at the beginning of the rule with no luck.
An example of what I have tried is below, in the WordPress .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /jobs/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /jobs/index.php [L]
RewriteRule /jobs/search/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)$ /jobs/search.php?search=$1&auth=$2&skills=$3&andor=$4×cale=$5&areas=$6&andor_areas=$7&posted=$8 [L]
</IfModule>
Joomla .htaccess file is below (shown as it comes with Joomla package):
##
# #version $Id: htaccess.txt 10492 2008-07-02 06:38:28Z ircmaxell $
# #package Joomla
# #copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
# #license http://www.gnu.org/copyleft/gpl.html GNU/GPL
# Joomla! is Free Software
##
#####################################################
# READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE
#
# The line just below this section: 'Options +FollowSymLinks' may cause problems
# with some server configurations. It is required for use of mod_rewrite, but may already
# be set by your server administrator in a way that dissallows changing it in
# your .htaccess file. If using it causes your server to error out, comment it out (add # to
# beginning of line), reload your site in your browser and test your sef url's. If they work,
# it has been set by your server administrator and you do not need it set here.
#
#####################################################
## Can be commented out if causes errors, see notes above.
Options +FollowSymLinks
#
# mod_rewrite in use
RewriteEngine On
########## Begin - Rewrite rules to block out some common exploits
## If you experience problems on your site block out the operations listed below
## This attempts to block the most common type of exploit `attempts` to Joomla!
#
# Block out any script trying to set a mosConfig value through the URL
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
# Block out any script that includes a <script> tag in URL
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Send all blocked request to homepage with 403 Forbidden error!
RewriteRule ^(.*)$ index.php [F,L]
#
########## End - Rewrite rules to block out some common exploits
# Uncomment following line if your webserver's URL
# is not directly related to physical file paths.
# Update Your Joomla! Directory (just / for root)
# RewriteBase /
########## Begin - Joomla! core SEF Section
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$ [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
#
########## End - Joomla! core SEF Section
The directory part of the URLs in the RewriteRule is the confusing part for me as I am not sure on how it should be constructed.
Also, could the Joomla or WordPress .htaccess rules be affecting the mod_rewrite that I am trying to attempt?
You placed your mod_rewite rule too low, it should be right after your RewriteBase /jobs/.
The caret symbol was missing from the mod_rewrite rule and has been added into my supplied Apache mod_rewrite .htaccess code. What you had was this: RewriteRule /jobs/search/ etc. but should have been this: RewriteRule ^/search/ etc.
Since you already declared the RewriteBase as /jobs/, RewriteRule /jobs/search/ etc. is not necessary and has to be changed to simply using RewriteRule ^/search/ etc. minus the /jobs/ part.
Additionally, I added in a temporary 307 re-direct, non case sensitive rule to the mod_rewrite rule.
The Apache mod_rewrite .htaccess Code
RewriteEngine On
RewriteBase /jobs/
RewriteRule ^/search/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*) /jobs/search.php?search=$1&auth=$2&skills=$3&andor=$4×cale=$5&areas=$6&andor_areas=$7&posted=$8 [R=307,NC,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /jobs/index.php [L]
Related
At root there is WordPress site. And in subdirectory calles 'vue' there is vue build is there. In wordpress URL if 'podcaster' or 'crowd' is not a part of a URL then I want to load vue page without changing browser URL.
Below is my folder structure
Target is:
www.example.com/podcaster //display in the address bar, points to WP (var/www/html/)
www.example.com/crowd //display in the address bar, points to WP (var/www/html/)
www.example.com/username //display in the address bar, points to VUE (var/www/html/vue)
www.example.com //display in the address bar, points to WP (var/www/html/)
Below is the WordPress root directory .htaccess:
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews
RewriteEngine On
# Rewrite rule for vue
RewriteCond %{REQUEST_URI} !^/crowd/
RewriteCond %{REQUEST_URI} !^/podcaster/
RewriteRule (.+) /vue/$1 [L]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Below is vue sub directory .htaccess:
# /vue/.htaccess
RewriteEngine On
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.html [L]
You've not stated exactly what the problem is, however...
RewriteCond %{REQUEST_URI} !/podcaster/
RewriteRule ^(.*)$ /vue/$1 [L,NC]
This will result in requests for the root being internally rewritten to the /vue subdirectory (I'm assuming you've placed this at the top of the WordPress .htaccess file in the root directory). You've stated that WordPress should be served from the root. In which case you should change the RewriteRule pattern from .* (0 or more) to .+ (1 or more) to avoid being triggered for requests to the root (base URL / homepage).
You will also need to ensure that rewritten requests (by the WordPress front-controller - to index.php - in the code that follows) are not also rewritten (otherwise everything will ultimately be rewritten to the /vue subdirectory). We can do this by adding another condition that checks against the REDIRECT_STATUS environment variable, which is empty on the initial request and set to 200 (as in 200 OK status) after the later rewrite.
UPDATE: And I suspect you also have a number of static resources (CSS, JS, images, etc) that also need to be excluded, so we probably need to add a filesystem check for those, so the request is not rewritten if it already maps to a file (or directory).
For example, bringing the above points together, this becomes:
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_URI} !/podcaster/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.+) /vue/$1 [L]
I've removed the NC flag as that was superfluous here. Note also that the condition is successful when the string "/podcaster/" (note that slashes) does not appear anywhere in the URL-path. Should this not be restricted to the start of the URL-path perhaps? eg. !^/podcaster/.
Also, where is the rest of the WordPress .htaccess file? The WordPress front-controller (the part that normally appears after the # BEGIN WordPress comment marker) should appear after your custom directive. If you place your custom rewrite at the end of the WordPress .htaccess file, after the WP front-controller section then your directive will not doing anything since all requests will be routed to WordPress.
Note that you should place your custom directives before the # BEGIN WordPress comment marker. You should never edit the code between the # BEGIN WordPress and # END WordPress comments since this block of code is maintained by WordPress and your code could be overwritten when WP updates (unless you take additional steps to prevent this). There is no need to repeat the RewriteEngine or <IfModule> directives.
Below is vue .htaccess which in "vue" sub directory
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteBase /vue/
RewriteRule ^vue/index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /vue/index.html [L]
</ifModule>
The Vue .htaccess file isn't quite right (although should work OK). The first RewriteRule directive (which is simply an optimisation) should not include the vue subdirectory in the regex. In other words, it should be written:
RewriteRule ^index\.html$ - [L]
Since the URL-path that is matched is relative to the filesystem path that contains the .htaccess file.
In fact, you can remove all instances of vue from this file (which makes it simpler and more portable), providing you also remove the RewriteBase directive entirely. For example:
# /vue/.htaccess
RewriteEngine On
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.html [L]
Relative substitution strings (ie. index.html in the 2nd RewriteRule directive above) are relative to the directory that contains the .htaccess file (providing you don't have a RewriteBase directive that states otherwise). So, the above naturally rewrites the request to /vue/index.html without having to explicitly state the directory.
I have a wordpress installation in the root and another one in a subfolder within the root.
What would normally happen is that the url would look like:
https://example.com/quotes/us/some-url
but I wanted to remove 'quotes' from the url so it just ended up like:
https://example.com/us/some-url
Thanks to another stack overflow user, I was able to get that to work with the below htaccess code but I didn't realise that the images are now not showing and I get a 404 error for all of them. This is the root .htaccess file
RewriteRule ^[a-z]{2}/ quotes%{REQUEST_URI} [L]
# BEGIN rlrssslReallySimpleSSL rsssl_version[3.3.5]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
# END rlrssslReallySimpleSSL
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<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
and the subfolder 'quotes' .htaccess looks like this
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule (.*) /$1 [R=301,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /quotes/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /quotes/index.php [L]
</IfModule>
# END WordPress
I get a 404 error to this path https://example.com/wp-content/themes/theme_quotes/style.css?ver=1.0.0. So, it is looking in the root installation where that theme doesn't exist as it only exists in the subdirectory installation
Currently, we only rewrite requests to the /quotes subdirectory when the URL-path starts with a 2-letter language code, since that is the only thing that appears to differentiate the URLs between the two WordPress installs. However, that means that URLs to your static resources (as above) that do not have the language code prefix (and do not reference the /quotes subdirectory directly) are not being rewritten and so fail with a 404.
This could perhaps be fixed in WordPress, by including /quotes in the URL to your static resources. But that does expose the /quotes subdirectory for anybody looking at your HTML source. We would also need to modify the redirect directive in the /quotes/.htaccess file to prevent these requests being redirected back to root. EDIT: Actually, it looks like this is happening with your images already which already include the full ("correct") URL-path.
What we could do... in the root .htaccess file, rewrite any request for a static resource (image, CSS or JS file) to the /quotes subdirectory if it doesn't exist in the root. For example:
# Rewrite any URLs that contain a language code prefix to the subdirectory
RewriteRule ^[a-z]{2}/ quotes%{REQUEST_URI} [L]
# Rewrite any request for a static resource that does not exist (in the root)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(css|js|png|jpg|webp|gif)$ quotes%{REQUEST_URI} [L]
# BEGIN WordPress
# : (Remainder of existing .htaccess file goes here)
This does mean that should you have two static resources with the same name (same base URL-path) in both installations then the one in the root installation will "win".
Note that this is a "blind" rewrite... if a particular static resource does not exist in either installation then you will always get the 404 in the /quotes installation. But there's no way to really resolve that since there is an element of ambiguity in the URL-path structure.
AND, in the /quotes/.htaccess file, prevent any direct requests for static resources being redirected back to the root. For example:
# Redirect any direct requests for "/quotes/<anything>" back to root
# Except for static resources
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_URI} !\.(css|js|png|jpg|webp|gif)$
RewriteRule (.*) /$1 [R=301,L]
# BEGIN WordPress
# : (Remainder of existing .htaccess file goes here)
I'm assuming all your file extensions (to static resources) are lowercase.
You will need to clear your browser cache, since the image redirect back to root will likely have been cached by the browser (since this is a 301 - permanent - redirect).
My server is Ubtuntu 18.04, OpenLiteSpeed, and Wordpress. With all plugins disabled, and using the default theme we are unable to publish or update posts/pages. This question looks similar to a lot of other ones but none of their solutions are working for me. My understanding of this issue is that maybe our htaccess file isn't being respected by OpenLiteSpeed, even though it is configured to do so. I have not edited the .htaccess file at all. Here are its contents:
# BEGIN LSCACHE
# END LSCACHE
# BEGIN NON_LSCACHE
# END NON_LSCACHE
### Forcing HTTPS rule start
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
### Forcing HTTPS rule end
# 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
I also get 404 error messages in the console for urls in this path: https://example.com/wp-json/wp/v2/*
I have tried updating the permalink structure multiple times to no avail, unless I add index.php to the structure. For example https://example.com/index.php/%postname%/. This allows us to visit posts, update them, etc.
It's great that we can have it working, but that index.php in the URL is just so darn ugly. What do I need to do to get rid of it?
If you are using rewriterule tab in webadmin console, instead of .htaccess
you will need to change the rule
from
RewriteRule ^index.php$ - [L]
to
RewriteRule ^/index.php$ - [L]
save and restart it.
there is slightly difference for rewrite rule when you place it in different place, mostly a forwarding slash like above one.
I've got .htaccess files looping on me.
The site is currently an old Joomla site which I'm trying to replace with a Word Press site.
I've installed WP in a subdirectory called /new. Once I'm happy with the WP site I'll delete the Joomla one.
At the moment if I try to access anything at www.mysite.com.au/new it wont load and I get an error message that I have too many redirects.
In the top level I have this
# #version $Id: htaccess.txt 423 2005-10-09 18:23:50Z stingrey $
# #package Joomla
# #copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
# #license http://www.gnu.org/copyleft/gpl.html GNU/GPL
# Joomla! is Free Software
##
#
# mod_rewrite in use
#
RewriteEngine On
# Uncomment following line if your webserver's URL
# is not directly related to physical file paths.
# Update YourJoomlaDirectory (just / for root)
# RewriteBase /YourJoomlaDirectory
#
# Rules
#
RewriteCond %{REQUEST_FILENAME} !\.(jpg|jpeg|gif|png|css|js|pl|txt)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php
RedirectMatch permanent ^/ContactUs.htm$ http://www.sitename.com.au/content/view/14/30/
RedirectMatch permanent ^/Contents.htm$ http://www.sitename.com.au/content/view/21/57
RedirectMatch permanent ^/new/$ http://www.sitename.com.au/new/index.php/
And in the /new directory I have this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /new/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /new/index.php [L]
</IfModule>
# END WordPress
I'm sure the answer is very simple, but I just cant see it... any suggestions ?
cheers
Try commenting out:
RedirectMatch permanent ^/new/$...
line to avoid infinite lopping.
The overall goal is to create a twitter-like site where if you try to go to any of the pages that are not indicated, you will be taken to a profile page instead. While this is somewhat simple in most cases it becomes a bit more complicated inside of Joomla due to the fact that the !-f command is a bit useless. Article titles don't actually exist so this one does not.
The only alternative that I have functioning is to list every page I don't want to redirect as a condition. The result is something like this. The Custom redirects is the section in question.
# Use PHP5.3 as default
AddHandler application/x-httpd-php53 .php
RewriteEngine on
#Options +FollowSymLinks
Options +SymLinksIfOwnerMatch
## Mod_rewrite in use.
## Begin - Rewrite rules to block out some common exploits.
# If you experience problems on your site block out the operations listed below
# This attempts to block the most common type of exploit `attempts` to Joomla!
#
# Block out any script trying to base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block out any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL.
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL.
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Return 403 Forbidden header and show the content of the root homepage
RewriteRule .* index.php [F]
#
## End - Rewrite rules to block out some common exploits.
## Begin - Custom redirects
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !how-it-works
RewriteCond %{REQUEST_FILENAME} !plans-and-pricing
RewriteCond %{REQUEST_FILENAME} !contact-us
RewriteCond %{REQUEST_FILENAME} !login
RewriteRule ^(.*)$ ./index.php?option=com_profiles&view=publica&Name=$1 [R=301]
## End - Custom redirects
## Begin - Joomla! core SEF Section.
#
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the request is for something within the component folder,
# or for the site root, or for an extensionless URL, or the
# requested URL ends with one of the listed extensions
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
#
## End - Joomla! core SEF Section.
Now this works perfectly with one minor hitch. It appears that the css for this page is actually using the referring page's. Joomla is made modularly so the template calls for a content section and the content section is being replaced while the rest is not. This includes header files linking to style sheets.
I was hoping some of the people here might be able to take a look at this and tell me what is preventing this from being a proper redirect. I don't really use htacess so some of the nuances are lost on me.