Prepending GET parameter to permalinks with Wordpress - php

I have a question about rewrite rules and WordPress permalinks. For the purposes of a localisation feature, I need to prepend a 'pretty' param at the beginning of all paths on a site. So for example, example.com/post-title would become example.com/en/post-title. To do this I was thinking of creating a rewrite rule in the .htaccess which would take a ?lang=en from the end of the url and transform it as described. Is this even possible with rewrite rules? And even if it is, would the permalinks in WP honour it or would they just revert to the link stored in the db for the post?

I would recommend using WPML or another plugin like this to work with different languages in WordPress. WPML will also solve your 'pretty' URL problem without rewrite etc.

Related

Is there access a php script on a wordpress theme

i have tried to load a flat panel write on PHP i put in a wordpress theme.
for alone the script run great but i want run that on wordpress theme.
problem in them routing. for example:
site/wp-content/themes/admin/dashboard/
site/wp-content/themes/admin/dashboard/sprofile
site/wp-content/themes/admin/dashboard/rprofile
can not access above route.
i think this solve with .htaccess file but don't know how !?
is there any way?!
If you're using wordpress you may want to create a shortcode for your script but, in case you don't want to, you can also use .htaccess with the rewrite module to redirect a url and access your panel.
Here are two examples that I hope will help you:
.htaccess rewrite examples
Shortcode examples
If I understood your situation correctly, you want to run a piece of PHP code which prints stuff inside the page as a feature in your WP theme. Not knowing the details, i can give you a couple of ideas:
If you need to embed that in an existing page (or s a new page itself), you need to create a template/template part and manage it trough wordpress's apis (which includes, as said, shipping it as a template part or a template itself, See codex)
If you need to create a new page with custom logic which is more suitable to be written as a plugin, consider adding a rewrite rule to a custom route (See this section of the codex and take a look at this article)
that is i want
when enter to
site/wp-content/themes/admin/dashboard/login
rewrite to
site/wp-content/themes/admin/dashboard/?url=login
login not static
now i use this to htaccess but don't work :
RewriteRule ^wp-content/themes/bluetheme/dashboard/(.*)$ /subdirectory/wp-content/themes/bluetheme/dashboard?url=$1 [L,NC,QSA]
Don't try cheating on WP, by smuggling your php file in some dir and trying to call it from there, by tweaking .htaccess file and similar. Look for system way to create custom WP page. I.e.
https://www.wpbeginner.com/wp-themes/how-to-create-a-custom-page-in-wordpress/

URL rewrite for one page

I have a bilingual wordpress site that adds the language subdomain into the URL (e.g., mysite.com/en/first-page/. I am trying to find a simple way (can it be done via the functions.php file?) to rewrite the URL to have it remove the /en/, making the URL mysite.com/first-page/. Is this possible? I've looked at some tuts and a lot of them focus on stuff like archives and categories and I'm not sure they can help me.
Since you asked for a functions.php solution, you may be able to use add_rewrite_rule(). Something like:
add_rewrite_rule('^first-page/?', 'en/first-page/');
If that doesn't work, you should consider adding a rule to .htaccess.

Remove "title" word in Main URL in wordpress

How do I remove ?title= in Main Website url in Wordpress
Sample URL:
http://mydomain.com/propertiesdetail?title=this-is-title
Please Help. Thank you.
As far as I can understand you want to have 'nice' URLs.
Wordpress has built-in SEO and user-friendly URL rewrite implementation. All you have to do is check your Permalinks settings in Administration area->Settings.
Select to use not the Default, but Post name (or anything else, you can see all the options). This way all website URLs will be 'beautified' automatically, because Wordpress will rewrite the .htaccess file with the correct code.

Display Text (Title of product) instead of long URL

I need to display Title of product instead of its url. For Exapmle instead of
localhost/test/index.php?option=com_spidercatalog&product_id=109&view=showproduct&page_num=1&back=1&show_category_details=1&display_type=cube&show_subcategories=1&show_subcategories_products=2&show_products=1&select_categories=1&Itemid=106
display localhost/test/catalog/product/257-Sony
Title and ID of post
P.S. working in joomla
This is URL Rewriting. You have to wrote rules for Apache or Nginx. If you're using Joomla, it can do it for you. More info here : http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html
You can try turn on Joomla seo->turn seo.
Or you can use SEO COMPONENTS such as located in Joomla extensions.
I recommend using sh404 + plugin to virtuemart.
You would first need to enable Joomla!'s SEF from the Global Configuration, and then write a router.php file for this component, if it doesn't have one.
See this: Supporting SEF URLs in your component

How to use mod_rewrite with Wordpress?

I'm running a wordpress installation on the root dir of my website test.com
Wordpress is using url's like: test.com/information/ and I also added some custom parameters like: test.com/information/?about=product
I tried to use the mod-rewrite generator at http://www.generateit.net/mod-rewrite/ to change my custom urls to test.com/information/about/product but keep receiving a wordpress 404 error.
Is there a solution to my problem?
All answers wrong. Login to admin area. On the left menu, under settings find permalinks. You can choose or add proper settings there.
I agree with #borayeris - Wordpress has it's own permalinks page under Settings - use that.
If you are already using pretty permalinks, make an about page then make it the parent page of all your product pages.
Or use the rule:
RewriteRule ^information/about/([^/]+)/?$ information/?about=$1 [L,NC]

Categories